Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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()?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.3k views
Welcome To Ask or Share your Answers For Others

1 Answer

  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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...