Created
January 2, 2022 13:26
-
-
Save matjahs/18f9fa503b36370fe63a4f649db08dae to your computer and use it in GitHub Desktop.
Async Generators
This file contains hidden or 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
async function * generateInput() { | |
yield 1; | |
yield 2; | |
yield 3; | |
} | |
async function * addOne (input) { | |
for await (const value of input) { | |
yield value + 1; | |
} | |
} | |
async function * timesTwo(input) { | |
for await (const value of input) { | |
yield value * 2; | |
} | |
} | |
async function main() { | |
const input = generateInput(); | |
for await (const n of addOne(timesTwo(input))) { | |
console.log(n); | |
} | |
} | |
main().catch(console.error); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment