cokol,

could you elaborate on the timer idea? namely, how do you block the current
executing method using a timer?

I'm sure I missed your point, but just for argument's sake, I cooked up this
method:
public void execute() {
  Timer blocker = new Timer() {
    public void run() {
      while (currentIdx < commands.size());  // 1
      this.cancel()  // 2
    }
  }

  DeferredCommand.addCommand(new IncrementalCommand() { /* checking if it's
busy, if not, get the next cmd and execute. increment currentIdx, etc etc */
});

  blocker.scheduleRepeat(100);  // 3
}

Now // 3 is supposed to help me block execute() method from returning,
except that // 1, the spinning lock locks the current thread, and // 2 is
never going to be called, because the incremental command never gets a
chance to execute, so currentIdx is going to stay the same.

I'm sure I'm doing it the wrong way, but I haven't figured out how a timer
can help me here. Maybe you can enlighten me.


On Fri, Aug 13, 2010 at 7:07 AM, cokol <eplisc...@googlemail.com> wrote:

> 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 <kevin.jing....@gmail.com> 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 google-web-tool...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-web-toolkit+unsubscr...@googlegroups.com<google-web-toolkit%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.
>
>

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

Reply via email to