News for hackers. Stuff that matters.
Re:A tour of JavaScript timers on the web by Waterluvian on Monday September 03, 2018 @06:43PM (#17905354)
Maybe I'm wrong but I always thought settimeout was far simpler than this blog goes on about. My understanding is that it puts a frame into the queue that keeps getting ignored until _at least_ timeout ms has elapsed.

Therefore, settimeout of 0 is to basically place a frame into the queue, "do this once the stack is empty and there's nothing in front of it in the queue."

They're just about placing frames into some place in the queue.

Is it not that simple?

Re:A tour of JavaScript timers on the web by jayflux on Monday September 03, 2018 @06:51PM (#17905382)
The timer basically runs in another thread, and once it’s finished it’s callback/frame goes into the queue, it does not go into the queue before the time you gave. The reason the time can’t be accurate is because other “frames” could be ahead of it in the queue after the timer has finished.
Re:A tour of JavaScript timers on the web by asknthrow on Monday September 03, 2018 @09:09PM (#17905893)
I don't think this is correct. AFAIK they both run in the UI thread (which is why running your timer in a webworker turns out to be more accurate as only the callback is affected by queue length of scheduled calls in the UI thread). Although this article https://www.html5rocks.com/en/tutorials/audio/scheduling is about sheduling audio specifically, it is the go-to resource for accurate web timing (and although not explicitly mentioned, the metronome is supposed to run in a webworker).
Re:A tour of JavaScript timers on the web by gsnedders on Monday September 03, 2018 @09:31PM (#17905997)
IIRC, zero is special cased and does something like jump to the front of the queue. But I've not worked on any of this in years!