如何在五次迭代后停止cron

时间:2016-02-03 12:54:18

标签: node.js

i的值大于5时,如何停止cron?

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');

2 个答案:

答案 0 :(得分:1)

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');

答案 1 :(得分:0)