Let's discuss two of the implementation methods of the Scheduled tasks:
1.setInterval ()
SetInterval () can call a function or evaluate an expression according to a specified period (in milliseconds);
The SetInterval () method will not stop calling the function until Clearinterval () is called or the window is closed. The ID value returned by setinterval () can be used as a parameter to the Clearinterval () method.
And among them:
The SetTimeOut () method is used to call a function or evaluate an expression after a specified number of milliseconds, execute code only once, and to invoke multiple times, use SetInterval ()
1.
2.https://thinkjs.org/zh-cn/doc/2.2/crontab.html
There is also a corresponding timer processing method in the thinkjs2.2 (3.0 the same method exists)
Node-crontab:https://github.com/dachev/node-crontab
In fact, in the process of use, I seem to find node-schedule https://github.com/node-schedule/node-schedule more popular. In fact, what kind of choice, with personal preference.
Timed tasks in the thinkjs2.2