जॉनीएचके ने मेरी त्रुटि की ओर इशारा किया। लाइब्रेरी का उपयोग करते हुए, Async - मैंने उसके उत्तर को दर्शाने के लिए कोड को समायोजित किया है:
function insertFeedItems(feedItems,newFeedID){
async.eachSeries(feedItems, function(item, eachCallBack) {
let firstName = item.author.substr(0, item.author.indexOf(' '));
let lastName = item.author.substr(item.author.indexOf(' ') + 1);
async.waterfall([
(callback) => {
authorController.createAuthorInternally(firstName, lastName, function(author) {
return callback(null, author, item.categories);
});
},
(author, categories, callback) => {
categoryController.createCategoryInternally(categories, function(categories) {
return callback(null, author, categories);
});
},
(author, categories, callback) => {
feedEntryController.createFeedEntry(item, author, categories, function(entry) {
return callback(null, author, categories, entry);
});
},
],
function(waterfallError) {
if(!waterfallError){
eachCallBack();
}
});
}, function(eachSeriesErr) {
if(eachSeriesErr) {
console.log('An item failed to process');
} else {
console.log('All items have been processed successfully');
}
});
}