Skip to content

Instantly share code, notes, and snippets.

@r37r0m0d3l
Forked from dtao/eachAsync.js
Created March 31, 2014 20:31
Show Gist options
  • Save r37r0m0d3l/9901567 to your computer and use it in GitHub Desktop.
Save r37r0m0d3l/9901567 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