Created
February 12, 2016 05:24
-
-
Save iptpv/8be2732a6a245787bf7c to your computer and use it in GitHub Desktop.
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
function asyncForeach(array, cb, stop) { | |
var index = 0; | |
function done() { | |
if (index > array.length - 1) { | |
return stop(); | |
} | |
cb(array[index], index, done); | |
index++; | |
}; | |
done(); | |
} | |
asyncForeach(['1', '2', '3'], function(item, index, done) { | |
setTimeout(function() { | |
console.log(item); | |
done(); | |
}, 1000); | |
}, function() { | |
console.log('end'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment