Function asCallback

  • Calls callback whenever the async generator produces a value.

    When using asCallback, call it with await to let generator run its course before continuing:

    await asCallback(tick({ interval:1000, loops:5 }), x => {
    // Gets called 5 times, with 1000ms interval
    });
    console.log(`Hi`); // Prints after 5 seconds

    Or if you skip the await, code continues and callback will still run:

    asCallback(tick({ interval: 1000, loops: 5}), x => {
    // Gets called 5 times, with 1000ms interval
    });
    console.log(`Hi`); // Prints immediately

    Type Parameters

    • V

    Parameters

    • input: AsyncIterable<V>
    • callback: ((v: V) => unknown)
        • (v): unknown
        • Parameters

          Returns unknown

    • OptionalonDone: (() => void)
        • (): void
        • Returns void

    Returns Promise<void>