Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.7k views
in Technique[技术] by (71.8m points)

js的setInterval定时器和node-schedule库有什么区别?

node-schedule库的底层也是setInterval这种定时器吗?只是前者的封装吗?相比js的setInterval这种定时器有什么优点?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

node-schedule有详细的介绍。

  1. node-schedule库的底层也是setInterval这种定时器吗?
    不是的,node-schedule底层依赖的是setTimeout
  2. 相比js的setInterval这种定时器有什么优点?
    实现简单的定时任务用setInterval还可以,但是复杂的或者超长延时的定时任务就无能为力了。比如每隔30天触发一次的定时任务(setInterval/setTimeout函数最大delay只有2^31 -1ms,大概24.8天)。node-schedule有详细的介绍。

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.7k users

...