Function withCallbackAdapter

  • Creates an async iterable queue that is populated with values from a provided factory function. The factory function is passed a CallbackAdapterContext object, which contains methods to pass values to the queue and mark the end of the iterable. The optional cleanup function can be used to perform cleanup operations when the queue is sealed.

    Returns

    A function that takes an input object and returns an IterableQueue.

    Example

    const someTarget = new EventEmitter();
    const eventQueue = withCallbackAdapter(
    (context, target) => target.on("someEvent", context.pass),
    (context, target) => target.removeListener("someEvent", context.pass)
    )(someTarget);

    (async () => {
    for await (const value of eventQueue) {
    console.log(value); // Logs event values as they are emitted
    }
    })();

    // Emit some events
    someTarget.emit("someEvent", "Hello");
    someTarget.emit("someEvent", "World");

    Type Parameters

    • T

      Type of the input object.

    • U extends unknown[]

      Tuple type representing the values passed to the queue.

    Parameters

    • factory: FactoryFn<T, U>

      A function that sets up the event listeners or other mechanisms to pass values to the queue.

    • Optional cleanup: CleanupFn<T, U>

      An optional function that performs cleanup operations when the queue is sealed.

    Returns ((input: T) => IterableQueue<U>)

Generated using TypeDoc