Recently had a code review where the distinction between setInterval
and setTimeout
under Node came up. Wanting to answer this question I put together some simple tests. The behavior of the two implementations, as of Node 0.10.30, was surprisingly reverse of my expecations, but there is a lot of nuance to how the event loop works in this case.
setInterval
's behavior is similar to what one would expect from a exec+setTimeout
loop. It's period is going to be it's exec time plus the interval value.
setInterval Delay: 50 Interval: 100 Wait mode: none