Function fromFunction

  • Access callback as an iterable:

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

    Use fromFunctionAwaited to await callback.

    Type Parameters

    • T

    Parameters

    • callback: (() => T)

      Function that generates a value

        • (): T
        • Returns T

    Returns Generator<T, void, unknown>