StreamClass.asyncStream<U, R>(source: Source<U>,fn: (value: Exclude<U, AnyFailure>,signal: AbortSignal) => R | PromiseLike<R>,options?: { maxConcurrency?: number; timeoutMs?: number; ordered?: boolean; }): StreamClass<Exclude<R, AnyFailure>,Extract<U | R, AnyFailure> | AnyFailure>
Elixir's Task.async_stream/3, living at its JS-idiomatic home: maps fn over the
source with at most maxConcurrency invocations in flight, lazily — nothing starts
until a consumer pulls, and the window refills only as results are taken. Results keep
source order by default (ordered: false yields completion order — faster when element
durations vary). Each element may deadline (timeoutMs) into a declared
Failure('AsyncTimeout') element — the railway, not a crash; the element's signal
fires so cancellation-aware work stops. A throw from fn stays a bug. Failure elements
from the source pass through unmapped.
const doubled = await Stream.asyncStream([1, 2, 3, 4], (n) => n * 2, { maxConcurrency: 2 }).collect(); doubled; // [2, 4, 6, 8] — at most 2 in flight at any moment