使用GWT调度程序

编程入门 行业动态 更新时间:2024-10-10 15:21:05
本文介绍了使用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调度程序

本文发布于:2023-11-25 09:28:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1629216.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:程序   GWT

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!