Skip to content

Instantly share code, notes, and snippets.

@richard-flosi
Created February 23, 2022 21:49
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 richard-flosi/99d4517e8d32aa4ebba1c76ca14de60b to your computer and use it in GitHub Desktop.
Save richard-flosi/99d4517e8d32aa4ebba1c76ca14de60b to your computer and use it in GitHub Desktop.
Example of *yield to pass proxy to another function compared to awaiting each next() value and applying a transformation before yielding
// When you just need to pass through the value yield from another generator function use:
yield* generatorFunction();
// When you need to manipulate each yielded value
const generator = generatorFunction();
let next = await generator.next();
while (!next.done) {
let value = next.value;
// TODO apply any transformations to value here
yield value;
next = await generator.next();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment