Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
453 views
in Technique[技术] by (71.8m points)

browser - Using the GWT Scheduler

I'm having a tough time understanding the difference between various methods of the com.google.gwt.core.client.Scheduler interface, specifically, the scheduleDeferred, scheduleFinally, and scheduleIncremental methods.

I'm hampered in my understanding, I think, by my unfamiliarity with the browser event processing loop, to which the Scheduler documentation refers.

Would you please explain how these methods differ from each other, and how they work in relation to the browser event loop?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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()


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...