padolsey / cron.js

Cron for JavaScript. Still in development.
123 stars 22 forks source link

i have a problem when use loop to create cron #6

Closed kira8565 closed 8 years ago

kira8565 commented 8 years ago

1、 var CronJob = require('cron').CronJob; for (var i = 0; i < 2; i++) { new CronJob('* * * * * *', consoleLog(i), null, true, 'America/Los_Angeles'); } function consoleLog(i) { console.log(i); }

when i run this code ,the job run only once and will not continute

2、 var CronJob = require('cron').CronJob; for (var i = 0; i < 2; i++) { new CronJob('* * * * * *', function () { console.log(i); }, null, true, 'America/Los_Angeles'); }

when i run the code above ,i get 2 2 rather than 0 1