JavaScript (in a browser) is single threaded. The event loop model means, we're always in exactly one of two states:
- in the event loop
- executing an event handler
There are many kinds of events: Click events, onload events, XHR events, timer events, ... You'll have to declare some handlers (at least one during page load), otherwise none of your code will ever be executed. One of them is the handler you specify by implementing onModuleLoad
.
It's important to keep all handlers short, because there's no parallelism and no interrupts (except for the last resort "unresponsive script" interrupt). This means, that users can't interact with the interface, until the browser returns to the event loop - and that doesn't happen before the current handler is finished.
So if you want to defer some code until after the other event handlers had a chance, then you can use Scheduler.scheduleDeferred
.
Scheduler.scheduleIncremental
helps you to split really long running tasks into multiple steps, giving the other event handlers a chance between each of the steps.
Scheduler.scheduleFinally
just means: After handling our current handler (even if an exception occurs), but before returning to the event loop, execute my command.
See com.google.gwt.core.client.impl.Impl.entry0()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…