eventDispatcherToAsyncIterator
eventDispatcherToAsyncIterator<
T>(dispatcher):AsyncIterable<T>
Defined in: packages/async/src/events/helpers/event-dispatcher-to-async-iterator.ts:31
Creates an async iterator over events emitted by the given IEventDispatcher.
Each time the dispatcher emits an event, the iterator yields the event arguments as an array.
Type Parameters
Section titled “Type Parameters”T extends unknown[]
Parameters
Section titled “Parameters”dispatcher
Section titled “dispatcher”The event dispatcher to convert into an async iterator.
Returns
Section titled “Returns”AsyncIterable<T>
An async iterable that yields event arguments as arrays.
Example
Section titled “Example” const dispatcher = new EventDispatcher<[number, string]>();
async function consumeEvents() { for await (const [num, str] of eventDispatcherToAsyncIterator( dispatcher, )) { console.log(`Received event with number: ${num} and string: ${str}`); } }
consumeEvents();
dispatcher.dispatch(1, "first"); dispatcher.dispatch(2, "second"); ```