Created
February 23, 2022 21:49
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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