Skip to content

Instantly share code, notes, and snippets.

@simov
Last active December 10, 2015 13:48
Show Gist options
  • Save simov/4442949 to your computer and use it in GitHub Desktop.
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.
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