2017-06-02 42 views
0
async.map(map, function(item, mnext){ 
    async.waterfall([ 
     function(wnext){ 
      console.log("1"); 
      //mongodb queryies something like 
      db.collection.find().toArray(function(err){ 
       if(err){ 
        wnext(err); 
       }else{ 
        wnext(); 
       } 

      }) 
     }, 
     function(wnext){ 
      console.log("2"); 
      //mongodb queryies something like 
      db.collection.find().toArray(function(err){ 
       if(err){ 
        wnext(err); 
       }else{ 
        wnext(); 
       } 

      }) 
     }, 
     function(wnext){ 
      console.log("3"); 
      //mongodb queryies something like 
      db.collection.find().toArray(function(err){ 
       if(err){ 
        wnext(err); 
       }else{ 
        wnext(); 
       } 

      }) 
     } 



    ], function(err){ 
     if(err){ 
      mnext(err); 
     }else{ 
      mnext(); 
     } 

    }) 
}) 

我期望根據地圖的數量看到1 2 3 1 2 3 1 2 3。但情況並非如我所料。我意識到它打印爲1 2 1 2 3 31 2 3以外的東西。我不明白這是怎麼發生的。因爲它是瀑布,結構是真的,我猜?那麼我們可以說地圖或瀑布有問題嗎?或者它async.map是異步的,所以它覆蓋瀑布?在地圖node.js中使用瀑布

我不知道..我被困住了。我在想什麼?預計序列是不是1 2 3

+1

你想['.mapSeries'](https://caolan.github.io/async/docs.html#mapSeries) –

+0

謝謝謝謝謝謝謝謝!你讓我今天一整天都感覺很好。我不知道 – mmu36478

回答