简体   繁体   English

在Node.Js脚本中使用Javascript Timer在特定时间触发事件

[英]Use Javascript Timer in Node.Js Script to fire an event at certain time

I have 40 or more timer in my Node script (a timer for per connection) to count time and call a function when it's finished. 我的Node脚本中有40个或更多的计时器(每个连接一个计时器),用于计算时间并在完成时调用一个函数。 For another job, i want call a function at 23:59; 对于另一项工作,我想在23:59调用一个函数; so i have two solution: 所以我有两个解决方案:

  1. Use another Java script timer to check time and call my function at 23:59. 使用另一个Java脚本计时器检查时间并在23:59调用我的函数。
  2. Use Linux schedule to emit an event at 23:59. 使用Linux计划在23:59发出事件。

Which is more logical? 哪个更合乎逻辑? Is there another solution? 还有其他解决方案吗?

Take a look at node-cron module, I've used this to schedule recurring tasks on Node apps before: 让我们看一下node-cron模块,在此之前,我已经使用它来安排Node应用程序上的重复任务:

Node Cron 节点克隆

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

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