1

I can know that a particular event is part of a compound operation, even a particular operation...

tags.addEventListener(gapi.drive.realtime.EventType.VALUES_SET,handleEvent);

function handleEvent(serialized) {
    if (serialized.compoundOperationNames.indexOf("LOTS OF TAGS CHANGING") > -1) {
};

...but how can I know that the compound operation is complete, and it's now a good time to do something about it?

I'd like to be able to do something like this:

if (serialized.lastCompoundOpEvent) {
    // Read all the tags and do an expensive bulk operation here
}
HeyHeyJC
  • 2,627
  • 1
  • 18
  • 27
  • Did you try using setTimeout to get a callback after the current sync block is finished? Once you've detected a change, queue up a timer which will handle your bulk operation. If you've determined that your 'expensive bulk operation' is a bottleneck, waiting the extra few ms for the timer to fire is probably worth it. – Grant Watters Jun 08 '15 at 20:44
  • Well, they're a bunch of separate events, so not in any sort of sync block. And any choice of timer duration would be arbitrary and likely to bite me at some point. Plus there's no guarantee, even if I've picked a time after the end of one compound op... that another one hasn't started meanwhile. – HeyHeyJC Jun 08 '15 at 22:25
  • What is the goal of finding the end of a compound operation? Is there a way to phrase the goal independent of the realtime api? (i.e. You want to wait for mutations on your data model to finish before running an expensive batch operation). Using setTimeout here gives you the opportunity to delay any expensive work after your are done processing data. – Grant Watters Jun 08 '15 at 22:34
  • Additionally as per https://developers.google.com/google-apps/realtime/model-events "Events are dispatched after the completion of the current synchronous block rather than executed immediately. This ensures all changes to the model are applied prior to executing the event handlers." It may be an implementation detail of the realtime API, but all the events for one compound operation are going to be fired in a single synchronous block rather than async. You should be able to verify this by setting a debugger in your event handler and looking at the event loop in the api. – Grant Watters Jun 08 '15 at 22:39
  • I think that the point may be that from the POV of the user making the changes, they are transactional (undoable en masse, etc). My question was really addressing the POV of another receiving user, who cannot know the extent of a compound op. I take the point that if the API really is dispatching them synchronously, any timer would have to wait... might be worth experimenting with. Cheryl's suggestion to wait for the ObjectChangedEvent works in this particular case, though. – HeyHeyJC Jun 08 '15 at 22:50
  • @GrantWatters Grant, do you know whether events are triggered locally BEFORE the realtime api talks to its servers? If so, then the local UI could react only to those events, without a (significant) delay. – HeyHeyJC Jun 24 '15 at 19:48
  • Local events *are* fired before the changes/data is sent to the server. I'm not sure what your goal with that information is, but generally a rule of thumb is as long as you're taking < 100ms to display updates to the user it is fast enough. – Grant Watters Jun 24 '15 at 20:01
  • The goal would be to update the local UI solely from realtime events, rather than the local user's actions, which (since I agree about the timing) could not be relied on to be timely if those events were triggered after interaction with the servers. – HeyHeyJC Jun 24 '15 at 22:24

1 Answers1

0

I don't think there is any way to do specifically what you list describe there.

If the goal is just find out all events for a particular compound operation, you could listen for ObjectChangedEvent. The one ObjectChangedEvent should include the list of all events for the compound op for the object and its children.

Cheryl Simon
  • 46,552
  • 15
  • 93
  • 82
  • Is only one ObjectChangedEvent generated for each object changed within a compound op? If so, that fits the bill perfectly. – HeyHeyJC Jun 08 '15 at 20:31