Skip to content

Instantly share code, notes, and snippets.

@jslatts
Created July 9, 2013 14:51
Show Gist options
  • Save jslatts/5957979 to your computer and use it in GitHub Desktop.
Save jslatts/5957979 to your computer and use it in GitHub Desktop.
Testing async.js callback behavior when returning errors.
Processing 1
Processing 2
Processing 3
Processing 4
Processing 5
[Error: Exploding on 5]
Processing 6
Processing 7
Processing 8
Processing 9
Processing 10
var async = require('async');
var boomArray = [1,2,3,4,5,6,7,8,9,10];
async.each(boomArray
, function(e, fn) {
console.log('Processing ' + e);
if (e === 5) {
return fn(new Error('Exploding on 5'));
}
else {
return fn(null);
}
}
, function(err) {
if (err) console.log(err);
else console.log('completed');
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment