The streaming module provides utilities for detecting, collecting, and caching async generator results in doc-kit’s processing pipeline.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/nodejs/doc-kit/llms.txt
Use this file to discover all available pages before exploring further.
isAsyncGenerator
Checks if a value is an async generator/iterable.Value to check
true if the value is an async iterable (has Symbol.asyncIterator), false otherwiseType Guard
This function acts as a TypeScript type guard:collectAsyncGenerator
Collects all values from an async generator into a flat array. Each yielded chunk is spread into the results array.Async generator yielding arrays of items
Promise resolving to flattened array of all yielded items
Debugging
The function logs collection progress:- Each chunk collected with item count
- Final summary with total items and chunk count
createStreamingCache
Creates a cache for async generator collection results. Ensures that when multiple consumers request the same async generator, only one collection happens and all consumers share the result.Cache object with
getOrCollect methodgetOrCollect
Gets the collected result for a generator, starting collection if needed.Cache key (usually generator name)
The async generator to collect
Promise resolving to collected results
Usage in Generator Pipeline
From the main generator orchestration (generators.mjs:20-43):
Implementation Details
Chunk Flattening
ThecollectAsyncGenerator function spreads each chunk with results.push(...chunk) rather than pushing chunks as nested arrays. This is because generators yield arrays of processed items, and the final result should be a single flat array.
Cache Key Strategy
The cache uses string keys (typically generator names) to deduplicate collection. Once a key is cached, subsequent calls return the same promise, preventing redundant collection work.Logging
All streaming utilities use thestreaming logger namespace for debug output, helping trace collection behavior during pipeline execution.