Build lazy data pipelines with JavaScript iterators
8 steps · about 4 h 20 min · Intermediate
- Learn the iterable and iterator protocols (guide, MDN, 35 min)
The protocols define how a consumer requests values and learns that production is complete.
- Implement a custom iterable (reference, MDN, 30 min)
A protocol-correct object can feed loops and other language consumers without exposing storage.
- Express a producer as a generator function (reference, MDN, 30 min)
Generator syntax preserves readable control flow while yielding values on demand.
- Compose generators with yield star (reference, MDN, 25 min)
Delegation lets one producer reuse another without manually forwarding every next call.
- Consume asynchronous values sequentially (reference, MDN, 30 min)
For-await-of waits for each value and naturally limits demand to the consumer's pace.
- Produce asynchronous values lazily (reference, MDN, 35 min)
Async generators combine awaited input with one-at-a-time output and explicit failure propagation.
- Connect iteration to a readable stream (guide, MDN, 40 min)
A stream reader shows how demand, cancellation and chunk production interact at an I/O boundary.
- Test completion, cancellation and producer errors (reference, MDN, 35 min)
Throwing into a generator makes failure handling and cleanup observable at a precise suspension point.