Skip to content

Instantly share code, notes, and snippets.

@garzito
Forked from dtao/eachAsync.js
Created April 8, 2016 22:46
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 garzito/67eb51e87d362920511cd1e3a0b6e98c to your computer and use it in GitHub Desktop.
Save garzito/67eb51e87d362920511cd1e3a0b6e98c to your computer and use it in GitHub Desktop.
Function to asynchronously iterate over a collection
function eachAsync(collection, iterator, callback) {
var iterate = function(i) {
setTimeout(function() {
iterator(collection[i]);
if (i < collection.length) {
iterate(i + 1);
} else {
callback();
}
}, 0);
};
iterate(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment