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

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

问题描述

我很难理解 com.google.gwt.core.client.Scheduler 接口的各种方法之间的区别,特别是 scheduleDeferredscheduleFinallyscheduleIncremental 方法.

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天全站免登陆