使用GWT调度 [英] Using the GWT Scheduler

查看:156
本文介绍了使用GWT调度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个艰难的时间理解 com.google.gwt.core.client.Scheduler 接口的各种方法之间的差异,具体而言, scheduleDeferred scheduleFinally scheduleIncremental 方法。

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?

推荐答案

的JavaScript(在浏览器)是单线程的。事件循环模式意味着,我们在两种状态正好一个总是:

JavaScript (in a browser) is single threaded. The event loop model means, we're always in exactly one of two states:


  • 在事件循环

  • 执行的事件处理程序

有很多类型的事件:点击事件,onload事件的事件,事件XHR计时器事件,......你必须声明一些处理(页面加​​载期间至少有一次),否则你没有code的永远不会被执行。其中之一就是你通过实现指定处理 onModuleLoad

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.

所以,如果你想推迟一些code,直到后其他事件处理程序有机会的话,那么你可以使用 Scheduler.scheduleDeferred

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 帮助您真正长时间运行的任务分割成多个步骤,让其他事件处理程序的每个步骤之间的机会。

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 只是意味着:在处理我们目前的处理器(即使发生异常)之后,但在返回到事件循环之前,执行我的命令。

Scheduler.scheduleFinally just means: After handling our current handler (even if an exception occurs), but before returning to the event loop, execute my command.

请参阅com.google.gwt.core.client.impl.Impl.entry0()

这篇关于使用GWT调度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆