JohnnyHK wees op mijn fout. Met behulp van de bibliotheek, Async - ik heb de code aangepast om zijn antwoord weer te geven:
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');
}
});
}