I was writing a server side job that was trying to throttle an operation by doing the following:
var throttle = 1000 / 20;
for (var i = 0; i < 80000; i++) {
setTimeout(operation, Math.floor(throttle * i));
}
I recognize that sleep works better here, but node.js required a library so I tried to tough it out. However, this program would work for over a thousand of these things, and then... nothing. No error message, just nothing happening. I suspect that JS ran out of timeout slots.
I have since migrated to sleep, which appears to be working, but I am curious as hell as to how JS is dealing with the timeouts. Does anyone have any additional insight?
Thanks!
For what it's worth, I assume that the answer is in this file https://github.com/joyent/node/blob/master/src/timer_wrap.cc assuming it's not in V8 itself.