Last active
December 10, 2015 01:19
-
-
Save Mithrandir0x/4357802 to your computer and use it in GitHub Desktop.
Asynchronous ForEach made by Zef Hemel
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
//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