async.each中的asynchronous函数没有被触发

任何人都可以解释下面的控制台日志打印的顺序吗? 我正在使用asynchronous版本1.4.23。
响应包含两个项目。
输出:标签1
标签2
标签2
标签4
标签3
标签3

async.parallel([ function(callback){ detailsData.list({}, function(err, response) { if (!err) { console.log("label 1"); async.each(response, function(item, cb) { console.log("label 2"); itemList.getData(item, function(err, response) { console.log("label 3"); } cb(err); }); }); } callback(err); }); }, function (callback) { somefunction(); }], function (err) { console.log("label 4"); } 

为什么在标签4之前不打印标签3?

您必须将从async.parallel获得的callback传递给async.each而不是立即调用它,否则并行执行不会等待每个callback

 async.parallel([ function(callback){ detailsData.list({}, function(err, response) { if (err) return callback(err); // <- still call it when you're not going for the each console.log("label 1"); async.each(response, function(item, cb) { console.log("label 2"); itemList.getData(item, function(err, response) { console.log("label 3"); cb(err, response); }); }, callback); // ^^^^^^^^ }); }, function(callback) { somefunction(); callback(); } ], function(err) { console.log("label 4"); });