async.waterfall node js 中的循环回调



我想在每个循环的 else 中执行回调。在我的控制台中,我写了"找到",但回调没有执行......

   async.waterfall([
      function readFile(callback){
        console.log("Start async");
        var params = {Bucket : "MyBucket", Key: "MyKey"};
        reads3.getObject(params, function extract(err,data) {
          //read a json object
          console.log("Start reading");
          callback(err,data);
         });
      },
      function(data, callback){
        var content = data.Body.toString('utf-8').trim();
        var jsonparse = JSON.parse(content);
          async.each(config, function(item) {
          var currentPath = item.path;
            if((key.search(currentPath)) === (-1)) {
              console.log("No found !");
            } else {
                console.log("Found");
                callback(jsonparse);
            }
          });
      },
      function(jsonparse){      
        console.log("In the 2nd loop !");
      }
    ]);

你能试试这个吗

 async.waterfall([
          function readFile(callback){
            console.log("Start async");
            var params = {Bucket : "MyBucket", Key: "MyKey"};
            reads3.getObject(params, function extract(err,data) {
              //read a json object
              console.log("Start reading");
              callback(err,data);
             });
          },
          function(data, callback){
            var content = data.Body.toString('utf-8').trim();
            var jsonparse = JSON.parse(content);
              async.each(config, function(item) {
              var currentPath = item.path;
                if((key.search(currentPath)) === (-1)) {
                  console.log("No found !");
                } else {
                    console.log("Found");
                    callback(null,jsonparse);
                }
              });
          },
          function(jsonparse,callback){      
            console.log("In the 2nd loop !");
            callback(null,'result');
          }
        ],function(err,data){
//your data is result
//......Your function script
});

相关内容

  • 没有找到相关文章

最新更新