I am trying to iterate over a collection in parallel and I was using async.forEach() for it, but I need to maintain the sort order too.
async.forEach(books, function (book, bookCallback) {
findBook(account, userinfo, permission, function (error, foundBook) {
if (error) {
bookCallback(error);
} else if (foundBook) {
bookCallback(account);
bookCallback(null);
} else {
bookCallback(null);
}
});
}, function (err) {
if (err) {
callback(err, null);
} else {
callback(null, finaCallback);
}
});
I have tried with async.map, async.groupBy, but even they did not maintain sort order. Only when I tried async.eachSeries order was maintained but it was not running in parallel.