In browsers, if you use setTimeout
from within a function called by setTimeout
then a minimum delay of 4ms will be enforced. Mozilla's developer wiki describes this behaviour, and mentions that it has become standardized in HTML5.
Node.js's documentation for setTimeout
does not mention a minimum delay. However, the documentation for the process.nextTick
function describes it as a more efficient alternative to setTimeout(fn, 0)
. This suggests the possibility that it's more efficient because it's avoiding this delay. Otherwise setTimeout(fn, 0)
could probably be optimized to behave the same.
Does Node.js enforce a minimum delay for setTimeout, as web browsers do?