I am working on GWT + JAVA.
I have a piece of code in GWT as below
static int DELAY = 1000;
private void downloadAttachments(final List<String> ftIdList)
{
try
{
Timer timer = new Timer()
{
@Override
public void run()
{
int cnt = 1;
for (String url: ftIdList)
{
String windowName = "win" + cnt;
Window.open(url, windowName, "");
cnt++;
scheduleRepeating(DELAY*2);
}
cancel();
}
};
timer.run();
}
catch (Throwable exc)
{
Window.alert(exc.getMessage());
}
}
I need to open several windows to allow a user to download all files.
I am calling a Servlet.
How can I introduce a delay in the loop until the next iteration?
Here is solution, in same style as maks suggests by using property for keeping the state of the counter. You still have the loop just in different way.