You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I believe this is not a problem of node-cron, but rather a question in javascript. The following code demonstrates the question. The cron job starts without any problem. However, it doesn't stop with the code setTimeout(job.stop, 5000), whereas it stops as expect with the following code:
// Stops as expectedsetTimeout(function(){job.stop();},5000);
varcronJob=require('cron').CronJob;varjob=newcronJob('* * * * * *',function(){console.log('You will see this message every second');});job.start();// Does not stop// setTimeout(job.stop, 5000); // Stops as expectedsetTimeout(function(){job.stop();},5000);
The text was updated successfully, but these errors were encountered:
This is due to scoping. The stop function uses this to identify the timeout to stop and to fire the onComplete callback. When you just provide the function pointer, the scoping isn't for the job, it is for the timeout which doesn't have the objects expected in this function (namely _timeout and onComplete).
I believe this is not a problem of node-cron, but rather a question in javascript. The following code demonstrates the question. The cron job starts without any problem. However, it doesn't stop with the code
setTimeout(job.stop, 5000)
, whereas it stops as expect with the following code:The text was updated successfully, but these errors were encountered: