Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@fitzgen
Last active August 29, 2015 13:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fitzgen/9866671 to your computer and use it in GitHub Desktop.
Save fitzgen/9866671 to your computer and use it in GitHub Desktop.
function* asyncIterator() {
let value, done;
while ({value, done} = (yield null), !done) {
console.log("got", value);
}
console.log("done");
}
it = asyncIterator();
it.next();
let i = 0;
(function loop() {
if (i > 10)
return it.next({ done: true });
it.next({ value: i++, done: false });
setTimeout(loop, 500);
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment