Prevent method call until Async Call Completes GWT-Platform

Bhavesh picture Bhavesh · Jun 18, 2012 · Viewed 8.7k times · Source

In my GWT-Platform application I have implemented method in which one step is to fetch data from server and next step is dependent on it. I want to prevent my method for further execution of the code until the Async call completes.

Should be something simple but I am not finding a way.

Answer

Ümit picture Ümit · Jun 19, 2012

I think you are missing the point about the web being asynchronous.

It is not considered good practice (it is rather an anti-pattern) to block the execution of your client side code until the async call is finished.

So instead of blocking the execution until your async code is finished do following:

  1. Create a Event which is fired on the global Eventbus when your async code is finished
  2. Attach a Handler for this event in one of your Presenters
  3. Start the async code
  4. Show a loading indicator
  5. When the async call is finished hide the loading indicator and fire the Event on the Eventbus
  6. Handle the next step in the Handler you created before.