简体   繁体   English

node.js中setTimeout的最大时间限制

[英]Maximum time limit of setTimeout in node.js

I have registered some setTimeout functions in node like below. 我已经在节点中注册了一些setTimeout函数,如下所示。

//Formula: minutes * 60 > seconds * 1000 > miliseconds.
setTimeout(() => {console.log("One minute")}, 1 * 60 * 1000)        //delay 60000
setTimeout(() => {console.log("Five minutes")}, 5 * 60 * 1000)      //delay 300000
setTimeout(() => {console.log("Ten minutes")}, 10 * 60 * 1000)      //delay 600000
setTimeout(() => {console.log("Thirty minutes")}, 30 * 60 * 1000)   //delay 1800000
setTimeout(() => {console.log("One hour")}, 60 * 60 * 1000)         //delay 3600000
setTimeout(() => {console.log("Two hours")}, 120 * 60 * 1000)       //delay 7200000
setTimeout(() => {console.log("Five hours")}, 300 * 60 * 1000)      //delay 18000000

Now the issue is setTimeout that take more than 10 minutes is not working when I read setTimeout documentation it's support 24.8 days . 现在,问题是setTimeout ,当我阅读setTimeout文档时,耗时超过10分钟setTimeout它支持24.8天

When delay is larger than 2147483647 or less than 1, the delay will be set to 1 当延迟大于2147483647或小于1时,延迟将设置为1

在此处输入图片说明

All delay's value is less than 2147483647 than why it is not working ??? 所有延迟的值都小于2147483647,这是为什么它不起作用的原因?

Finally I got answer when I created issue on node.js repo, basically it's not node.js but heroku issue. 最后,当我在node.js库上创建问题时,我得到了答案,基本上不是node.js,而是heroku问题。
In heroku free dynos are unique because they go to sleep after 30 minutes of inactivity so more than 30 minutes of time is not working 在heroku中, 自由测功机是独特的,因为它们在30分钟不活动后便进入睡眠状态,因此超过30分钟的时间无法正常工作
Github issue Github问题

I am not sure what you exactly want to achieve here. 我不确定您到底想在这里实现什么。 If you want to execute something at later stage use Cron instead of setTimeout . 如果要在以后执行某些操作,请使用Cron而不是setTimeout

And answer to your original question is 回答你原来的问题是

JavaScript store the delay as a 32-bit signed Integer internally. This causes an Integer overflow when using delays larger than 2147483647, resulting in the timeout being executed immediately.

Above code is working fine. 上面的代码工作正常。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM