Function fromFunctionAwaited

  • Access awaited callback as an iterable:

    const fn = () => Math.random();
    for await (const v of fromFunctionAwaited(fn)) {
    // Generate infinite random numbers
    }

    callback can be async, result is awaited. This requires the use of for await. Use fromFunction otherwise;

    Type Parameters

    • T

    Parameters

    • callback: (() => T | Promise<T>)
        • (): T | Promise<T>
        • Returns T | Promise<T>

    Returns AsyncGenerator<Awaited<T>, void, unknown>