问题
In the current stable version of node.js v0.10.33 there is a bug where setTimeout/setInterval does not fire anymore when setting the system time to the past.
Run this code to see what I mean:
var i = 0;
var handle = setInterval(function()
{
console.log(++i);
}, 1000);
Then while it's running change the time of your system to the past, does not matter if on windows or linux. The interval / timeout will not fire anymore. When chaning the time to the future, node behaves perfectly fine and keeps running the interval. This bug was fixed in node v0.11.3 which I cannot use yet because it is not stable.
I tried modules like timer-shim and nanotimer but they internally use setInterval/setTimeout aswell and thus have the same problem.
For the time being, how can I woraround this node bug for my application in the best possible way without funky monkey patching?
回答1:
This is fixed in older versions of the 0.10 branch: https://nodejs.org/en/blog/release/v0.10.36/
来源:https://stackoverflow.com/questions/27458602/how-to-workaround-a-nodejs-stable-bug-with-setinterval-settimeout-when-changing