Skip to content

Instantly share code, notes, and snippets.

@wiledal
Last active December 19, 2015 07:19
Show Gist options
  • Select an option

  • Save wiledal/5917764 to your computer and use it in GitHub Desktop.

Select an option

Save wiledal/5917764 to your computer and use it in GitHub Desktop.
Delayed for-loop for async operations Usage: dfor(tasks.length, function(i, next) { // Do task with i next(); }, function() { // All completed }
dfor = function(num, func, callback) {
var i = -1;
function next() {
i++;
if (i == num) {
end();
}else{
func(i, next);
}
}
function end() {
callback();
}
next();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment