我試過aysnc.eachOfSeries,但代碼沒有循環。它會在第一次迭代中停止執行並凍結。我想我在回覆回調時出錯了。Async.eachOfSeries不循環
我也嘗試在else塊中放置回調,但給回調已經調用錯誤。
這個async.eachOfSeries嵌套在另一個eachOfSeries中。
async.eachOfSeries(data, function (value2, val, callback) {
let jsonObj = data[val];
let email = jsonObj.ToEmail;
jsonObj['retailer'] = res[camp].retailer;
jsonObj['summary'] = 'f';
let tempObj = {};
tempObj[id] = jsonObj;
let options = { new: true};
let campId = id;
User.addCampaignResponse(email, campId, tempObj, options, function (err, results) {
if (err) {
throw err;
} else {
console.log("gets printed once");
Campaign.updateResponse(_id, function (err, results2) {
if (err)
throw err;
else {
console.log("Gets printed once");
callback(); //tried this but gives callback already called error
}
}) // console.log(results);
}
})
}, function (err) {
console.log("Doesn't print");
callback();
})