Dealing with asynchronicity in the start event

4 views
Skip to first unread message

Googelybear

unread,
Oct 29, 2010, 2:32:56 AM10/29/10
to mv...@googlegroups.com
Hi all,

I have the following scenario: In the start event I load the base application data from the backend. Since it's gwt this is asynchronous. My problem now is, that the next event is already fired before all data is loaded. e.g. Think of the history converter: at start 'start' is fired and afterwards the first event defined in the converter that will try to acces this data but fail since it might not be there yet.

The only solutions that come to my mind are:
1. Use busy waiting in the start method (sucks, browser gets unresponsive during that)
2. Ditch the start event functionality and do everything myself

What do you think? How did you solve that problem?

Thanks for any suggestions!

Den

Pierre

unread,
Oct 29, 2010, 7:36:53 AM10/29/10
to Mvp4g
Hi Den,

When you have history, your application will either call an history
converter or the init event. So instead of retrieving the data with
the start event, you can retrieve it in your history converter and
with the init event. If you use inheritance, this means you will have
to define data retrieval twice (one in your super history converter or
one in your init handler).

You could also create an event to retrieve data. This event will have
one parameter, the event to fire when the data is retrieved:

Command cmd = new Command(){

public void execute(){
eventBus.oneEvent(...);
}

}
eventBus.retrieveData(eventBus.oneEvent(...));



void onRetrieveData(final Command cmd){

getData(new AsynCallback(){

public void onSuccess(...){
cmd.execute();
}
});

}

Pierre

Dennis

unread,
Nov 5, 2010, 1:21:49 PM11/5/10
to Mvp4g
Hei Pierre,

great idea - I'll give it a try tomororw.

thanks,
Den

Dennis

unread,
Nov 8, 2010, 10:39:45 AM11/8/10
to Mvp4g
Hi Pierre,

just wanted to report back. Your suggestion worked perfectly fine for
me.

I now have an event 'loadBaseData(Command)' that loads the base data
and afterwards executes the given command. The @InitHistory annotation
is now on the 'loadBaseDataAndShowInitialScreen' event (loads base
data via 'loadBaseData' and afterwards shows the first screen). Also
the history convertres use 'loadBaseData' and trigger their events in
the passed command.

thanks again,
Den
Reply all
Reply to author
Forward
0 new messages