Function throttle

  • Emits each value after the callback result resolves, to control/mitigate the processing flow.

    The resolved value itself is ignored.

    import {pipe, toAsync, tap, throttle} from 'iter-ops';

    const i = pipe(
    toAsync([1, 2, 3, 4, 5]),
    throttle(async (value, index, state) => {
    await processValue(value);
    }),
    tap(value => {
    // value = 1, 2, 3, 4, 5 (each delayed by processing time)
    })
    );

    Type Parameters

    • T

    Parameters

    • cb: ((value, index, state) => Promise<any>)
        • (value, index, state): Promise<any>
        • Parameters

          Returns Promise<any>

    Returns Operation<T, T>

    Throws

    Error: 'Operator "throttle" requires asynchronous pipeline' when used inside a synchronous pipeline.

    See