Skip to content

Instantly share code, notes, and snippets.

@ianwalter
Last active January 28, 2017 14:09
Re-writing mariusa's example from https://github.com/caolan/async/issues/114
async.parallel({
a: function(callback) {
fs.readFile('a.html', 'utf8', function(err, a) {
if (err) callback(err);
console.log('read a');
callback(null, a);
});
},
b: function(callback) {
fs.readFile('b.html', 'utf8', function(err, b) {
if (err) callback(err);
console.log('read b');
callback(null, b);
});
}
}, function (err, results) {
console.log('a:' + results.a);
console.log('b:' + results.b);
});
@cvrabie
Copy link

cvrabie commented Jan 28, 2017

You know this is incorrect right? The callback would get called twice in the parallel functions. Either place the second callback in an else block or use if (err) **return** callback(err);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment