write a class which can be used like this:

Executor.async(cmd1).async(cmd2).async(cmd3).sync(cmd4)

it gonna start cmd1..cmd3 and when all are finished it gonna start
cmd4
and go for observer pattern

everytime an async call finishes it checks if it was the last one, if
so it triggers cmd4,
being in java you could have implemnted the lock with .wait()
and .notify() but in javascript its not possible where yu have to
write an own blocker, which imitates the wait() on java side, for this
you can use a timeout with maximum waiting time looping forever, so
the browser prevents execution, your executor should then implement
clearTimeout() which is called upon every async call termination
causing the timer to terminate and iterating with the next operation

On 12 Aug., 16:30, Kevin Qiu <[email protected]> wrote:
> I don't know if the title makes sense but working with gwt for about 2
> years, I often find myself in the position to mix both asynchronous and
> synchronous (blocking) apis. It's easy to transform a synchronous call to
> asynchronous, but the other way around is not immediately obvious to me,
> especially in the context of the single-threaded browser environment.
>
> Imagine I the following:
>
> abstract class GetList<T> {
>   abstract void execute(AsyncCallback<List<T>> callback);
>
> }
>
> class GetContactList extends GetList<Contact> {
>   void execute(AsyncCallback<List<Contact>> callback) { /* implementation */
>
> }
> }
>
> class GetAddressList extends GetList<Address> {
>   void execute(AsyncCallback<List<Address>> callback) { /* implementation */
>
> }
> }
>
> class GetPhoneList extends GetList<Phone> {
>   void execute(AsyncCallback<List<Phone>> callback) { /* implementation */ }
>
> }
>
> now imagine I keep a list of GetList objects:
> List<GetList> commands = Arrays.asList(new GetContactList(), new
> GetAddressList(), new GetPhoneList());
>
> and I have an executor that executes these commands:
>
> class Executor {
>   List<? extends GetList<?>> commands;
>   Executor(List<? extends GetList<?>> commands) {
>     this.commands = commands;
>   }
>   void execute() {
>   // XXX:
>   }
>
> }
>
> Now, for whatever reason, I need my execute() method to be a blocking call
> (synchronous). It should terminate after all GetList calls are returned. How
> can I achieve this?

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to