async.eachSeries in node.js

后端 未结 2 1904
伪装坚强ぢ
伪装坚强ぢ 2020-12-15 08:53

I have a loop in node.js

for (var i in files){
    var all = fs.readdirsync(\"./0\");
    async.eachSeries(all, function(item){
        check(it         


        
2条回答
  •  Happy的楠姐
    2020-12-15 09:25

    Outer loop needs to be async also. One of the the methods is to use 2 eachSeries loops or outer loop can be in parallel (each) if the files don't have to be processed in series:

    var async = require('async');
    
    async.eachSeries(files, function(file, outCb) 
    {
      var all = fs.readFileSync(file);
    
      async.eachSeries(all, function(item, inCb) 
      {
        check(item);
        inCb(null);  // inner callback
      }, 
      function(err) 
      {
        outCb(null);  // outer callback
      });
    },
    function(err) 
    {
      console.log('all done!!!');
    });
    

提交回复
热议问题