Brandon Benvie <mailto:[email protected]>
January 21, 2012 7:37 PM
Correction: it is specified in HTML5 here
http://www.whatwg.org/specs/web-apps/current-work/multipage/timers.html#timers.
Suffice to say that a DOM specification isn't sufficient for something
so central to JavaScript, nor is it the specification currently
followed by browsers anyway.
Browsers definitely have to agree on things such as this step:
* If timeout is less than 4, then increase timeout to 4.
And the modern ones, AFAIK, do (old ones use 10). THe spec is not the
same for Node.js and we cannot unify toward 1ms resolution given web
compatibility constraints found out the hard way (most recently by
Chrome folks).
Possibly it's time to try again, but whatever the case: what's required
is an experimental regime, not a rushed de-jure standardization mis-step
in ECMA-262.
We've considered setTimeout/setInterval/setImmediate, along with event
loop concurrency (also in HTML5). They won't make ES6. Maybe next time,
but IMHO we need more convergence between browsers and Node, and more
inductive learning.
/be
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss
Brandon Benvie <mailto:[email protected]>
January 21, 2012 7:26 PM
I just finished answering this question on StackOverflow and it got me
thinking about the obvious: timers are not specified yet are central
to a vast swath of JavaScript code. Timers in Node.js have a
significantly higher resolution than what is found in browsers:
`setTimeout(fn, 1)` will, in fact, execute in 1 millisecond (assuming
the system isn't taxed to the point of being unresponsive). Browsers
have collectively implemented a floor at around 15ms. Code that works
fine in a browser can very well melt the computer if run in Node. For
reference, here's the answer I wrote on StackOverflow;
It doesn't have a minimum delay and this is actually a compatibility
issue between browsers and node. Timers are completely unspecified and
node implements them simply due to how fundamental they've been in
JavaScript's history and how irreplaceable they are otherwise.
Node uses libuv which a cross-platform abstraction layer for lower
level system things like file-system, networking stuff, etc. One of
those things is timers, which Node provides a minimal wrapper around.
At the libuv level, the timers used are the system-specific high
precision timers. In Windows, for example, this is implemented using
|QueryPerformanceFrequency| and |FileTimeToSystemTime| which provides
resolution measured in nanoseconds.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms644905(v=vs.85).aspx
<http://msdn.microsoft.com/en-us/library/windows/desktop/ms644905%28v=vs.85%29.aspx>
http://msdn.microsoft.com/en-us/library/windows/desktop/ms724280(v=vs.85).aspx
<http://msdn.microsoft.com/en-us/library/windows/desktop/ms724280%28v=vs.85%29.aspx>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss