Skip to content

Instantly share code, notes, and snippets.

@nathankleyn
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathankleyn/0b0c75bd549220c3eb6b to your computer and use it in GitHub Desktop.
Save nathankleyn/0b0c75bd549220c3eb6b to your computer and use it in GitHub Desktop.
An example of JavaScript generators.
function *asyncThing1() {
someAsyncFn(function(val) {
yield val;
});
}
function *asyncThing2(arg) {
someOtherAsyncFn(arg, function(val) {
yield val;
});
}
function *asyncThing3(arg) {
someOtherAgainAsyncFn(arg, function(val) {
yield val;
});
}
var result = asyncThing1().next(),
result2 = asyncThing2(result).next(),
result3 = asyncThing3(result2).next();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment