Async JavaScript
Async Iteration & Streams
Async iterables represent values that arrive over time, and streams represent chunked data flow with backpressure. They are useful when data is large, incremental, or unbounded.
- Async iterables are consumed with
for await...of - Streams process chunks instead of whole payloads
- Backpressure prevents memory blowups
- Chunk boundaries are not semantic boundaries
- Collecting everything defeats streaming
for await (const chunk of stream) {
await processChunk(chunk)
}| Concept | Meaning | Example |
|---|---|---|
| Async iterable | Values arrive over time | for await...of |
| Readable stream | Source of chunks | HTTP response body |
| Writable stream | Sink for chunks | File upload target |
| Transform stream | Chunk-to-chunk processing | Compression / parsing |
| Backpressure | Consumer slows producer | Avoid memory growth |