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"),
);

Explanation

The generator pulls the next chunk only when the writer is ready. An error anywhere destroys all streams and rejects the promise.

Further reading

Problem with a question

Node.js · Senior · question 23

Test yourself

Take the Node.js · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz