Skip to content

Instantly share code, notes, and snippets.

@ashwinkumar2438
Last active March 20, 2021 12:38
Show Gist options
  • Save ashwinkumar2438/87d8ef86064177dd51e24788b6daaa25 to your computer and use it in GitHub Desktop.
Save ashwinkumar2438/87d8ef86064177dd51e24788b6daaa25 to your computer and use it in GitHub Desktop.
let childgen=function*(){
yield 'child 1';
yield 'child 2';
return 'child 3';
}
let parentgen=function*(){
yield 'parent 1';
yield 'parent 2';
let lastchild=yield* childgen();
return lastchild;
}
let ancestry=parentgen();
console.log(ancestry.next()); //@yields {value: "parent 1", done: false}
console.log(ancestry.next()); //@yields {value: "parent 2", done: false}
console.log(ancestry.next()); //@yields {value: "child 1", done: false}
console.log(ancestry.next()); //@yields {value: "child 2", done: false}
console.log(ancestry.next()); //@returns {value: "child 3", done: true}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment