running flux

10 views
Skip to first unread message

Marcão

unread,
Jan 3, 2012, 6:34:43 AM1/3/12
to Google Web Toolkit
Hi all.

I'd like to know if is possible to have a situation like this:

// code here

Timer timer = new Timer(){
public void run(){
System.out.println("some action here");

};

};

timer.schedule(2000);

// code here
System.out.println("action to be executed AFTER timer call");

The output that i want is:

"some action here"
"action to be executed AFTER timer call"

The output that i have:

"action to be executed AFTER timer call"
"some action here"

Thanks!

Jens

unread,
Jan 3, 2012, 6:49:30 AM1/3/12
to google-we...@googlegroups.com
Sure but you have to think asynchronous. So you have to start your code that depends on the Timer in its run() method either directly or by firing an event, e.g.:

Timer timer = new Timer(){ 

     public void run(){ 
         System.out.println("some action here"); 
         onTimerDone(); //or eventBus.fire(new OnTimerDoneEvent()); if multiple classes are interested 
     }; 

}; 

timer.schedule(2000); 

.....

private void onTimerDone() {
  System.out.println("action to be executed AFTER timer call");
  // your code
}
Reply all
Reply to author
Forward
0 new messages