Created
October 11, 2016 13:33
-
-
Save juanpaco/046c1b580bc5de1742927c2d29d655f0 to your computer and use it in GitHub Desktop.
Options for nested `async.eachSeries`. In response to http://stackoverflow.com/questions/21184340/async-for-loop-in-node-js/21184964?noredirect=1#comment67220656_21184964
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') | |
async.eachSeries( | |
[ 1, 2, 3 ] | |
, function (key, next) { | |
async.eachSeries( | |
[ 4, 5, 6 ] | |
, function (key, innerNext) { // note the name change | |
somethingAsync('something' + key, innerNext) // using the inner one | |
} | |
, function (innerErr) { | |
next(innerErr) // note the call to the outer one so that an inner error bubbles out | |
} | |
) | |
} | |
, function (err) { | |
console.log('iterating done') | |
} | |
) |
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') | |
function innerAsyncSeries(key, done) { | |
async.eachSeries( | |
[ 4, 5, 6 ] | |
, function (key, next) { // note the name change | |
somethingAsync('something' + key, next) | |
} | |
, function (err) { | |
done(err) // note the call to the outer one so that an inner error bubbles out | |
} | |
) | |
} | |
async.eachSeries( | |
[ 1, 2, 3 ] | |
, innerAsyncSeries | |
, function (err) { | |
console.log('iterating done'); | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment