Skip to content

Instantly share code, notes, and snippets.

@agrath
Forked from dtao/eachAsync.js
Created June 3, 2015 03:28
Show Gist options
  • Save agrath/b99c1d74d5254f6ebd6b to your computer and use it in GitHub Desktop.
Save agrath/b99c1d74d5254f6ebd6b 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-1) {
iterate(i + 1);
} else {
if(callback) callback();
}
}, 0);
};
iterate(0 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment