Created
July 9, 2013 14:51
-
-
Save jslatts/5957979 to your computer and use it in GitHub Desktop.
Testing async.js callback behavior when returning errors.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Processing 1 | |
Processing 2 | |
Processing 3 | |
Processing 4 | |
Processing 5 | |
[Error: Exploding on 5] | |
Processing 6 | |
Processing 7 | |
Processing 8 | |
Processing 9 | |
Processing 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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