Reputation: 23
How can I stop cron when value of i
is grater than 5?
var i=0
new testCron('1 * * * * *', function()
{
try
{
http.get(url,function(err,response)
{
if(err && i<5)
{
temp[i]=err;
console.log("its err no",i);
i++;
}
else
{
console.log("its reach in else");
}
}
)
throw err;
}
catch(e){
}
}, null, true, 'Asia/Kolkata');
Upvotes: 0
Views: 199
Reputation: 754
var i = 0
new testCron('1 * * * * *', function () {
if(i == 5)
process.exit(); // <---- program will terminate
try {
http.get(url, function (err, response) {
if (err && i < 5) {
temp[i] = err;
console.log("its err no", i);
i++;
} else {
console.log("its reach in else");
}
})
throw err;
} catch (e) {
}
}, null, true, 'Asia/Kolkata');
Upvotes: 1
Reputation: 1627
You have to use exit()
(alias of die()
) function.
Reference:
http://www.w3schools.com/php/func_misc_exit.asp
http://www.w3schools.com/php/func_misc_die.asp
Upvotes: 0