Wednesday, October 26, 2016

HowTo use GWT EvenBus to schedule OpenEvent -> CloseEvent sequence

[ Original post on StackOverflow ]

Say we have few handlers for both events. The goal is to make sure, that all OpenEvent handlersfinish before any of CloseEvent handlers start their job. The old EventBus had a reverse order flag, which sometimes helped greatly in these particular cases. I.e. a handler, responsible for launching some process which leads to CloseEvent being fired (i.e. event emitter), usually registers itself to a bus first.

Now, due to a synchronous nature of javascript each handler of OpenEvent ends his job before the next handler starts. In my app the first OpenHandler added to a bus is a CloseEvent emitter. Therefore I get an undesirable sequence of calls: 1st handler of OpenEvent -> all CloseEvent handlers -> the rest of OpenEvent handlers.

My question is: what's the best practice to establish the desirable behavior? So far as a workaround I use Scheduler.scheduleDeferred(Scheduler.ScheduledCommand cmd) to enqueueEventBus.fireEventFromSource(Event event, Object source) of CloseEvent call to the next browser's event loop tick.

p.s. My current thoughts are as follows. I don't want to rely of Timer or Scheduler (though it might be the only option, which I'm not sure about). Also I have no interest in introducing any flag variables, responsible for tracking which event occurred first. Instead, if one looks closer into theSimpleEventBus code, there's a firingDepth counter variable, which only works to delayaddHandler(...) and removeHandler(...) calls. It would be great, if same logic could be applied to order call sequences of handlers for different events.

You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
For more options, visit

No comments:

Post a Comment