Skip to main content

Function: eventStream()

eventStream<T>(emitter, event, options?): AsyncIterableIterator<T>

Defined in: util/eventStream.ts:19

Turns an emitter event into an async iterable, so it can be consumed with a linear for await loop instead of callbacks.

Events that arrive between iterations are buffered, so none are lost. The stream ends when the signal aborts, when the consumer breaks out of the loop (return()), or when one of endEvents fires. It deliberately ignores the emitter's 'error' event so a non-fatal error does not break the loop.

Type Parameters

T

T

Parameters

emitter

EventEmitter

event

string

options?

EventStreamOptions = {}

Returns

AsyncIterableIterator<T>