Function throttle

  • Throttles the input iterable, only yielding elements at most every ms milliseconds. Elements that are not yielded are discarded. Returns an async iterable that yields elements from the input iterable, but throttled.

    Returns

    A function that accepts an input iterable and returns a throttled async iterable.

    Example

    const input = asyncIterable(...);
    const throttledInput = throttle(1000)(input);

    (async () => {
    for await (const value of throttledInput) {
    console.log(value); // Logs elements with at least 1000ms delay between each log
    }
    })();

    Type Parameters

    • T

      The type of elements in the input iterable.

    Parameters

    • ms: number

      The minimum number of milliseconds between each yielded element.

    Returns ((input: AnyIterable<T>) => AsyncIterable<Awaited<T>>)

      • (input: AnyIterable<T>): AsyncIterable<Awaited<T>>
      • Parameters

        Returns AsyncIterable<Awaited<T>>

Generated using TypeDoc