0
在node.js中,我想有一個foreach async.parallel在另一個。不過,我得到了「回調已被稱爲」錯誤(看看我的代碼的評論)。我想要在內部完成後調用外部的回調函數。我怎樣才能做到這一點?NodeJS async.parallel在另一個async.parallel
async = require("async");
var asyncTasks = [];
var items = [];
/* push elements to items */
items.forEach(function(item){
var asyncTasks2 = [];
var items2 = [];
asyncTasks.push(function(callback2){
item.someAsyncCall(function(){
/* push elements to items2 */
items2.forEach(function(item2){
item2.someAsyncCall(function(){
callback2();
})
}
asyncTasks2.push(function(callback2){
setTimeout(function(){
callback2();
}, 100000);
});
async.parallel(asyncTasks2, function(){
// All tasks are done now
doSomethingOnceAllAreDone();
callback(); // callback was already called
});
});
});
});
asyncTasks.push(function(callback){
setTimeout(function(){
callback();
}, 100000);
});
async.parallel(asyncTasks, function(){
// All tasks are done now
doSomethingOnceAllAreDone();
});
讀http://stackoverflow.com/questions/25712767/nesting-node-async-eachseries –