Google+环聊应用共享数据对象中的数据不一致?

时间:2015-07-27 23:01:48

标签: google-plus hangout

使用submitDelta,setValue,clearValue和getState设置和获取值时,我得到的结果不一致。看起来这些是异步方法,因此我的同步命令(例如,console.log)使用本地数据对象执行。然后最终共享数据对象更新,然后更新本地数据对象。这是正确的评估吗?有没有办法同步运行这些数据命令,即在继续执行程序之前等待共享数据对象更新?

2 个答案:

答案 0 :(得分:0)

是的,环聊API中的数据操作是异步的。为了实现同步性,你必须听取onStateChanged events,并且只能继续你在这些事件中所做的一切。

将为所有参与者以及触发更改的本地参与者调用该事件。

答案 1 :(得分:0)

It doesn't look possible to write synchronous shared data object calls because if you have more than one onStateChange in your code, they all fire together. In other words, I can't tie one shared data object update to one onStateChange.

It looks like Google+ Hangouts executes database APIs in this order:

  1. Getting and setting values in the local data object (using getState)

  2. Getting values from the shared data object using getState.

  3. Changing values in the shared data object (setValue, clearValue, submitDelta, etc.).

  4. onStateChange to listen for shared data object changes.

The following (pseudo)code

=iferror(vlookup($a2, sheet2!$a:$c, column(b:b), false), "")

would return

setValue('counter', '11') getValue('counter') onStateChanged (getValue('counter')) submitDelta( {'counter': '22'} ) getValue('counter') onStateChanged (getValue('counter')) clearValue('counter') getValue('counter') onStateChanged (getValue('counter')) submitDelta( {'counter': '33'} ) getValue('counter') onStateChanged (getValue('counter'))

because the four getValues execute first, then setValue, submitDelta, clearValue, and submitDelta execute, then the four onStateChanged execute together, four times each because the shared data object is changed four times.

Does that sound right?