lib, Async.
:
import each from 'async/each';
var elements = [1, 2, 3, 4, 5, 6];
each(elements, function(el, next) {
console.log('Processing element ' + el);
callAsyncFunction(next);
}, function(err){
if( err ) {
console.log('A file failed to process');
} else {
console.log('Async processing is finished.');
}
});
:
each(myPosts, function(post, next) {
getPostAuthor(post.authorID, function(postAuthor) {
post.author = postAuthor;
next()
});
}, function(err) {
if (!err) {
res.render('index', {
posts: myPosts
});
res.end();
}
});