On 08/12/2010 12:50 PM, Kevin Qiu wrote:
> After some thought, I don't think putting it in IncrementalCommand and
> execute with DeferredCommand help much here. Jeff, If I understand you
> correctly, my execute method will look like this:
> 
> class Executor {
>   // declaration of list of commands
>   void execute() {
>     DeferredCommand.addCommand(new IncrementalCommand() {
>       boolean executing;
>       int currentIdx;
> 
>       public boolean execute() {
>         if (executing) return true;  // executor will keep looping
>         // it's my turn now
>         executing = true;
>         AsyncCommand cmd = commands.get(currentIdx);
>         cmd.execute(new AsyncCallback() {
>           public void onFailure(Throwable e) { onSuccess(null); }
>           public void onSuccess(Object o) {
>             executing = false;
>             ++currentIdx;
>           }
>       }
>       // return point
>   }
> }
> 
> The above method is actually still non-blocking. There's no guarantee
> that my incremental command will finish executing before I reach
> //return point. Did I miss anything?

Looking at your code a bit more closely (and while composing an
example), I see that you want something that requires a bit more structure.

You have the IncrementalCommand() correctly implemented. Forget my
previous answer.

Now that I really understand what you're asking (I think)...

I solve the problem using a state machine. Notice how the SM loops on
DICTIONARYREAD until the command queue is empty.

DeferredCommand.addCommand(new IncrementalCommand() {
  @Override
  public boolean execute() {
    switch (startupState) {
      case INITIAL:
        timer.scheduleRepeating(600);
        startupState = StartupState.DICTIONARYREAD;
        break;

      case DICTIONARYREAD:
        if (dictionaryRequest.getDictionaryPages()) {
           break;
        }

        startupState = StartupState.FINAL;
        break;

      case FINAL:  // Kevin's RETURN POINT?
        timer.cancel();
        return false; // command is complete
      }
    return true;
});

public boolean getDictionaryPages() {
 while (dictionaryRequestList.size() > 0) {
    if (busy) {
      return true;
    }
    dictionaryRequestList.pop().execute(); // RPC and BUSY mutex
 }
 return false;
}

-- 
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