An asynchronous generator produces a sequence of values over time with asynchronous semantics. It combines generator syntax with async iteration, making Promise-based data sources readable piece by piece. section 9.0 section 9.2.3
async function* someAsyncGen() {
}
Declare an asynchronous generator with the async function* signature, then consume its results with for await...of. section 9.2.3
Use asynchronous generators when a computation should expose data incrementally rather than assemble everything first.
- Read large asynchronous sources such as files, databases, or HTTP responses in chunks, using a moving window instead of loading the entire collection. section 9.0 section 9.2.3
- Separate stream production from downstream work: one generator can yield parsed objects while consumers count, validate, or transform them. section 9.2.3
Streaming blocks from a file
generateBlocksFromFile reads a file stream, collects complete semicolon-delimited records, parses each JSON block, and yields each object. A consumer can then use for await...of to count blocks or validate them incrementally, skipping the genesis block when necessary. section 9.2.3


