I know GWT is single threaded by nature, however I am trying to user deferred command to emulate a multi-threaded effect. I am trying to implement a text animation which is controlled by the isBusy boolean variable, which the text manipulation (animation effect) runs unti isBusy gets false value, when the server responded already. However this code seems to get stuck with the while-loop?
Here is the code:
loginButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
isBusy = true; // boolean
// Show animating effect...
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
while(isBusy == true) {
for (int i=0;i<3;i++) {
if (i==0) { loginButton.setText("."); }
if (i==1) { loginButton.setText(".."); }
if (i==2) { loginButton.setText("..."); }
}
}
}
});
loginService.getUser(usernameBox.getText(), passwordBox.getText(), new AsyncCallback<User>() {
@Override
public void onSuccess(User result) {
isBusy = false;
}
@Override
public void onFailure(Throwable caught) {
isBusy = false;
}
});
}
});
Scheduler was the right tool, but you are using the wrong command. You have to use scheduleFixedPeriod insdead of scheduleDeferred. Here is a small example which showes hopefully helps you.