Last active
December 19, 2015 07:19
-
-
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
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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