Created
February 4, 2015 13:38
-
-
Save guyellis/a39c4c3127652c9deeb1 to your computer and use it in GitHub Desktop.
async.eachSeries()
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 arr = [1,2,3,4]; | |
async.eachSeries(arr,function(item, cb){ | |
setTimeout(function() { | |
console.log('#1: ', item); | |
return cb(); | |
}, Math.random()*2000); | |
}, function(err){ | |
console.log('#1 Final call ', err); | |
}); | |
console.log('#1 should print first'); | |
async.eachSeries(arr,function(item, cb){ | |
setTimeout(function() { | |
console.log('#2: ', item); | |
return cb(); | |
}, Math.random()*2000); | |
}, function(err){ | |
console.log('#2 Final call ', err); | |
}); | |
console.log('#2 should print second'); | |
/* | |
Example output: | |
#1 should print first | |
#2 should print second | |
#2: 1 | |
#1: 1 | |
#1: 2 | |
#2: 2 | |
#1: 3 | |
#1: 4 | |
#1 Final call undefined | |
#2: 3 | |
#2: 4 | |
#2 Final call undefined | |
*/ |
You probably don't need this in modern JS. Look to use something from promise-fun
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cant understand