2 ms·
> Closure & timer – a deadly combo In practice you can avoid this problem if your function wrapping a timer is not a method and the callback of the timer is a
by austincheney 9y ago
> Closure & timer – a deadly combo
In practice you can avoid this problem if your function wrapping a timer is not a method and the callback of the timer is a recursive call to the very function wrapping the timer. In that case there is no object to access to get to the timer's function and secondly the this function never nullifies or removes from garbage collection until the last timer is called.
> setImmediate over setTimeout(fn,0)
Yes, agreed, but I wouldn't ever run timers in a loop to achieve parallel asynchronicity. I would use native Node methods to achieve this. I would however use timers to achieve sequential asynchronicity, also known as polling, which is where setTimeout would be beneficial. Sequential operations likely to always be slower than parallel operations, but sometimes you only just need intermittent delays.
I agree that these recommendations in the article are really good ideas.