Is there a way to stop execution of next function of series with async in nodejs?

前端 未结 4 1017
深忆病人
深忆病人 2021-02-14 06:13
  async.map(list, function(object, callback) {
    async.series([
      function(callback) {
        console.log(\"1\");

        var booltest = false;
        // assumi         


        
4条回答
  •  南笙
    南笙 (楼主)
    2021-02-14 06:54

    I'm passing an object to differentiate between an error and just functionality. Which looks like:

    function logAppStatus(status, cb){
      if(status == 'on'){
        console.log('app is on');
        cb(null, status);
      }
      else{
        cb({'status' : 'functionality', 'message': 'app is turned off'}) // <-- object 
      }
    }
    

    Later:

    async.waterfall([
        getAppStatus,
        logAppStatus,
        checkStop
    ], function (error) {
        if (error) {
          if(error.status == 'error'){ // <-- if it's an actual error
            console.log(error.message);
          }
          else if(error.status == 'functionality'){ <-- if it's just functionality
            return
          }
    
        }
    });
    

提交回复
热议问题