JavaScript equivalent of SwingUtilities.invokeLater()

怎甘沉沦 提交于 2019-11-28 09:37:55

问题


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

UPDATE 1

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


回答1:


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

  2. 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).

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.

See also

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


来源:https://stackoverflow.com/questions/8947034/javascript-equivalent-of-swingutilities-invokelater

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!