8 ms·
> Even if you’ve been doing JavaScript for a while, you might be surprised to learn that setTimeout(0) is not really setTimeout(0). Instead, it could run 4 mill
by jayflux 1y ago
> Even if you’ve been doing JavaScript for a while, you might be surprised to learn that setTimeout(0) is not really setTimeout(0). Instead, it could run 4 milliseconds later:
Is this still the case? Even with this change? https://chromestatus.com/feature/4889002157015040 https://chromestatus.com/feature/4889002157015040
- swsieber 1y agoI think it's still the case. The 4ms happens if you call setTimeout nested several times. I don't know the exact limit. But it's 5-ish times where that kicks in IIRC. Edit: Here's the MDN bit on that, I was correct: https://developer.mozilla.org/en-US/docs/Web/API/Window/setTimeout#reasons_for_delays_longer_than_specified https://developer.mozilla.org/en-US/docs/Web/API/Window/setT... > browsers will enforce a minimum timeout of 4 milliseconds once a nested call to setTimeout has been scheduled 5 times. And the link from there to the spec about that: https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#timers https://html.spec.whatwg.org/multipage/timers-and-user-promp... > If nesting level is greater than 5, and timeout is less than 4, then set timeout to 4.
- timhh 1y agoI think that change is talking about the minimum timeout for the first 5 nested calls to `setTimeout(0)`. Previously the first 5 would take 1ms, and then the rest would take 4ms. After that change the first 5 take 0ms and the rest take 4ms.