Skip to content

Instantly share code, notes, and snippets.

@shrunyan
Forked from dtao/eachAsync.js
Created October 17, 2013 15:57
Show Gist options
  • Save shrunyan/7027473 to your computer and use it in GitHub Desktop.
Save shrunyan/7027473 to your computer and use it in GitHub Desktop.
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