Joel Stevick

Episode 2 of 2 · 3:56

Async Generators in TypeScript: Why They're a Must for Streaming

What this episode covers

Reading an LLM's streamed answer in TypeScript, written two ways and compared: one async function with an onToken callback, and three async generators, for chunks, lines and tokens, with one for await loop. What the comparison shows: the mixed jobs that share one loop and one buffer; stopping early with break instead of an AbortController; how return() and errors pass through the chain of generators; and testing each generator alone.

At the end: both versions in one public repository, generators.ts against without-generators.ts, each with its tests, to run and compare yourself.