@ac-essentials/misc-util
    Preparing search index...

    Function eventDispatcherToAsyncIterator

    • 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

      • T extends unknown[]

      Parameters

      • dispatcher: IEventDispatcher<T>

        The event dispatcher to convert into an async iterator.

      Returns AsyncIterable<T>

      An async iterable that yields event arguments as arrays.

      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");