Wednesday, November 2, 2011

Re: problems with loading stuff/bootstrapping onModuleLoad triggered by an event

Grrr.

onModuleLoad() {
   // launch task 1
   // launch task 2
   // display wait message, or whatever
}

onTask1Finished() {
    task1Finished = true;
    maybeContinue();
}

onTask2Finished() {
    task2Finished = true;
    maybeContinue();
}

maybeContinue() {
    if (task1Finished && task2Finished) {
       // we're running from an event dispatch so handlers we add to the EventBus are deferred, and firing an event synchronously wouldn't trigger them, so we defer the whole thing
       Scheduler.get().scheduleFinally(new ScheduledCommand() {
          @Override
          public void execute() {
             // create your activity handlers, then:
             historyHandler.handleCurrentHistory();
          }
       });
    }
}

The first 3 methods you already have, the last one too, just missing that damn Scheduler bit; i.e. 5 damn lines.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/JLkTwwU0F7QJ.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment