Reviewers: jgw, bruce,
Message:
@Joel and Bruce,
Please take a look at this API, which is similar to what we had
discussed last week. I'll follow up tomorrow with a set of test cases.
This is the last piece we need to make StyleInjector operate efficiently
with the recommended UiBinder / inject-on-init pattern.
Description:
This change adds a scheduling API that has two new features:
- a "finally" command, which allows work to be performed just before
GWT code exits into the browser's event loop
- a lightweight implementation of timers, deferred commends, and
incremental commands which avoids using the JRE types.
A test application (below) averages 5.7k when written with this new API.
Writing a similar app that uses the existing DeferredCommand API
averages 18k.
public class Hello implements EntryPoint {
private static class MyRepeatingCommand implements RepeatingCommand {
int count = 0;
String prefix;
MyRepeatingCommand(String prefix) {
this.prefix = prefix;
}
public boolean execute() {
Scheduler.scheduleFinally(new MyScheduledCommand("F" + prefix +
count));
add(prefix + count++);
return count < 10;
}
}
private static class MyScheduledCommand implements ScheduledCommand {
String prefix;
MyScheduledCommand(String prefix) {
this.prefix = prefix;
}
public void execute() {
add(prefix);
}
}
private static void add(String str) {
DivElement elt = Document.get().createDivElement();
elt.setInnerHTML(str);
Document.get().getBody().appendChild(elt);
}
public void onModuleLoad() {
Scheduler.scheduleFixedDelay(new MyRepeatingCommand("A"), 500);
Scheduler.scheduleFixedPeriod(new MyRepeatingCommand("B"), 800);
Scheduler.scheduleIncremental(new MyRepeatingCommand("C"));
Scheduler.scheduleFinally(new MyScheduledCommand("D"));
}
}
Please review this at http://gwt-code-reviews.appspot.com/77820
Affected files:
A user/src/com/google/gwt/core/client/Scheduler.java
M user/src/com/google/gwt/core/client/impl/Impl.java
A user/src/com/google/gwt/core/client/impl/SchedulerImpl.java
--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---