如何在更改系统时间时使用 setInterval/setTimeout 解决 nodejs 稳定错误 [英] How to workaround a nodejs stable bug with setInterval/setTimeout when changing system time

查看:105
本文介绍了如何在更改系统时间时使用 setInterval/setTimeout 解决 nodejs 稳定错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在当前稳定版的 node.js v0.10.33 有一个错误,在将系统时间设置为过去时,setTimeout/setInterval 不再触发.

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);

然后在它运行时将系统时间更改为过去,无论是在 windows 还是 linux 上都没有关系.间隔/超时将不再触发.当将时间更改为未来时,节点表现得非常好并保持运行间隔.这个bug在node v0.11.3中修复了,我还不能用,因为它不稳定.

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.

我尝试了像 timer-shimnanotimer 但他们在内部使用 setInterval/setTimeout 以及因此有同样的问题.

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?

推荐答案

此问题已在 0.10 分支的旧版本中修复:https://nodejs.org/en/blog/release/v0.10.36/

This is fixed in older versions of the 0.10 branch: https://nodejs.org/en/blog/release/v0.10.36/

这篇关于如何在更改系统时间时使用 setInterval/setTimeout 解决 nodejs 稳定错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆