JavaScript等效于SwingUtilities.invokeLater() [英] JavaScript equivalent of SwingUtilities.invokeLater()

查看:126
本文介绍了JavaScript等效于SwingUtilities.invokeLater()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Javascript中, SwingUtilities 的Java的 invokeLater()方法是否相同?

Is there any equivalent of Java's invokeLater() method of SwingUtilities in Javascript?

更新1

因此, setTimeout()零延迟与 invokeLater()完全相同?

So, will setTimeout() with zero delay do exactly the same as invokeLater()?

推荐答案


  1. 如果你想异步运行某些东西(稍后),试试 setTimeout()

  1. If you want to run something asynchronously (later), try setTimeout()

JavaScript是单线程的。如果要在事件处理程序之外运行一些耗时(CPU密集型)任务,可以使用上面的技术执行此操作,但是它仍然会使用事件处理线程(导致UI冻结)。

JavaScript is single-threaded. If you want to run some time consuming (CPU-intensive) task outside of the event handler, you can do this using the technique above, however it will still consume event-handling thread (cause your UI to freeze).

在浏览器中运行CPU密集型任务通常是个坏主意(网络工作者可能会改变这种情况)因为他们与事件处理程序共享相同的线程,使他们等待。

It is generally a bad idea to run CPU-intensive tasks inside a browser (web workers might change this) since they share the same thread as event handlers, making them wait.

  • Are there any atomic javascript operations to deal with Ajax's asynchronous nature?

这篇关于JavaScript等效于SwingUtilities.invokeLater()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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