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

查看:174
本文介绍了使用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事件,定时器事件, ...你必须声明一些处理程序(在页面加载期间至少有一个),否则你的代码不会被执行。其中一个是通过实现 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.

所以如果你想延迟一些代码,直到其他事件处理程序有机会,那么你可以使用 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天全站免登陆