Skip to content

Instantly share code, notes, and snippets.

@Mithrandir0x
Last active December 10, 2015 01:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mithrandir0x/4357802 to your computer and use it in GitHub Desktop.
Save Mithrandir0x/4357802 to your computer and use it in GitHub Desktop.
Asynchronous ForEach made by Zef Hemel
//http://zef.me/3420/async-foreach-in-javascript
function asyncParForEach(array, fn, callback) {
var completed = 0;
if(array.length === 0) {
callback(); // done immediately
}
var len = array.length;
for(var i = 0; i < len; i++) {
fn(array[i], function() {
completed++;
if(completed === array.length) {
callback();
}
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment