1. Promise pipeline
stream/promises exposes a pipeline() that returns a promise and cleans up on error.
import { pipeline } from "node:stream/promises";Typorithm · hard
Step 1 of 8 · intro card
Streams
Backpressure is a slow Writable signaling a fast Readable to pause so memory does not balloon. .pipe() and pipeline() honor it automatically; manual .write() loops must check the return value. for await...of consumes a Readable as an async iterator, and stream/promises pipeline() chains streams while rejecting on error and cleaning up.
Backpressure is the mechanism by which a slow Writable tells a fast Readable to pause, so unconsumed data does not pile up in memory.
.pipe() and pipeline() apply backpressure automatically. If you write manually in a loop, you must check the boolean that .write() returns and wait for the 'drain' event when it is false.
for await...of treats a Readable as an async iterator, pulling one chunk per loop iteration with natural backpressure. The pipeline() from stream/promises chains streams, rejects its promise on any error, and cleans up every stream's resources.
Backpressure = a slow Writable pausing a fast Readable.
.pipe() and pipeline() honor backpressure automatically.
for await...of consumes a Readable as an async iterator.
import { pipeline } from "node:stream/promises";
for await (const chunk of readable) {
process.stdout.write(chunk);
}
await pipeline(source, transform, destination);Connect each part of the code to the concept before you type.
stream/promises exposes a pipeline() that returns a promise and cleans up on error.
import { pipeline } from "node:stream/promises";for await...of consumes a Readable as an async iterator, one chunk at a time.
for await (const chunk of readable) {Manual .write() returns false when the buffer is full; honoring that return value is how you respect backpressure by hand.
process.stdout.write(chunk);pipeline() chains streams, honors backpressure, rejects on error, and tears down resources.
await pipeline(source, transform, destination);Read the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.