Function delay

  • Delays each value by the specified timeout. When the timeout is a negative number, no delay added.

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

    const data = [1, 2, 3, 4, 5]; // some synchronous data

    const i = pipe(
    toAsync(data), // make asynchronous
    delay(1000)
    );

    for await(const a of i) {
    console.log(a); //=> 1, 2, 3, 4, 5 (with 1s delay)
    }

    Type Parameters

    • T

    Parameters

    • timeout: number

    Returns Operation<T, T>

    Throws

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

    See

  • Delays each value by the specified timeout (as returned from the callback). When the timeout is a negative number, it is not added.

    Note that it doesn't support return of Promise<number> on purpose, to avoid confusion with what operator throttle does.

    Type Parameters

    • T

    Parameters

    • cb: ((value, index, state) => number)
        • (value, index, state): number
        • Parameters

          Returns number

    Returns Operation<T, T>

    Throws

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