Thanks for taking the time. Although it's not clear what action you put in the timer and what the timer is supposed to do (IncrementalCommand is executed by DeferredCommand.CommandExecutor and it already has a timer with timeslice set to 100ms). Also, I suppose you need to reset the "busy" flag in the callback of the asynchronous calls.
I'm still a bit incredulous but I'll give it a try. Thanks again :) Cheers, On Thu, Aug 12, 2010 at 4:43 PM, Jeff Chimene <[email protected]> wrote: > 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]<google-web-toolkit%[email protected]> > . > 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 [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.
