import { pipeline } from 'stream/promises' const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)) const colorsGenerator = async function* () { const values = [ 'yellow', 'orange', 'red', 'blue', 'purple', 'green' ] for await (const color of values) { yield color await sleep(1000) } } const wordUpperCaser = async function* (source) { for await (const chunk of source) { yield chunk.toUpperCase() } } const letterUnderscorer = async function* (source) { for await (const chunk of source) { yield chunk.split('').join('_') } } const chunkLogger = async function (source) { for await (const chunk of source) { console.log(chunk) } } await pipeline(colorsGenerator, wordUpperCaser, letterUnderscorer, chunkLogger)