Search code examples
gwtasynchronousgwt-rpcsingle-threaded

GWT Single threaded async callbacks


rpc.call(mycallback);

{
//subsequent code block

}
  1. How does the single threaded async callback work?
  2. When will the callback get called?
  3. Will the subsequent code block always finish executing before the callback is allowed to run (i.e. will the callback only run once all code has finished?)?

Solution

  • #1 javascript is single-thread, but the browser is not, so the js-thread sends the xhr call to the browser to resolve it, and the browser returns the control to it inmediately.

    #2 when the browser gets the response from the server, it queues the callback into the js thread, so it will be executed when js finishes whatever it could be executing now (in your case the subsequent code block)

    #3 yes it will, because the single threaded execution of this block prevents the execution of any other deferred code (timeouts, callbacks) until it is finished.