Last active
December 10, 2015 13:48
-
-
Save simov/4442949 to your computer and use it in GitHub Desktop.
The `list` function is looping through a list of asynchronous operations.
The `main` function is notified about the state of the `list` function on each step.
This file contains 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
function list (step, end) { | |
function loop (index) { | |
if (index == 10) return end(); | |
step(index, function next () { | |
loop(++index); | |
}); | |
} | |
loop(0); | |
} | |
function main () { | |
list(function step (index, next) { // event on each step | |
console.log(index); | |
next(); | |
}, function end () { | |
console.log('end'); | |
}); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment