Node.js · Senior · Question 23 of 75
What does an async generator in pipeline give you?
await pipeline(
createReadStream("in.csv"),
async function* (source) {
for await (const chunk of source) yield transform(chunk);
},
createWriteStream("out.csv"),
);- 1A way to run the transform on another thread
- ✓Correct answer: A transform step written as plain async code, with backpressure and error handling still managed by
pipeline - 3Automatic parallel processing of all chunks
Explanation
The generator pulls the next chunk only when the writer is ready. An error anywhere destroys all streams and rejects the promise.