Joined April 2013
·

Matt Johnson

Technical Architect at Kaonix
·
UK
·
·
·

@twolfson I am aware it is not entirely cross-browser, and I would recommend the NobleJS implementation in a heartbeat (which uses something like the code above for browsers that support it). My intention was only to make other developers aware that there are problems with setTimeout and setInterval - but also that there are alternatives. Thank you for your contribution in making others aware. Also - I'm not sure Mozilla want to support it, see: It meets resistance both from Gecko (Firefox) and Webkit (Google/Apple).

@vraa you're correct, setTimeout and setInterval do not offer threading and Javascript is single threaded, although it can appear to the novice that the opposite is true. Therefore in my opening paragraph I refer to both asynchronicity and threads - my intention was avoid confusion, but I can see how it might be confusing.
Additionally, setTimeout and setInterval (even setImmediate) will push the execution at the end of a loop in Javascript, however, there is an imposed delay of (typically) 4ms. I'm aware that Chrome has tried to reduce this to 2ms but has had issues. I should also add that in some tests the postMessage implementation executes faster than the browser imposed delay in setTimeout and setInterval.

Achievements
128 Karma
8,059 Total ProTip Views