@jiminp/tooltool
    Preparing search index...

    Function rateLimited

    • Wraps an async function to enforce a minimum delay between consecutive executions.

      Additional calls are queued and processed in FIFO order. Useful for throttling API calls.

      Type Parameters

      • ArgsType extends unknown[]

        Tuple of the function's parameter types.

      • T

        The resolved return type.

      Parameters

      • fn: (...args: ArgsType) => Promise<T>

        The async function to rate-limit.

      • duration_ms: number | (() => number)

        Minimum delay (ms), or a function returning the delay dynamically.

      Returns RateLimitedFunction<ArgsType, T>

      A RateLimitedFunction.

      const limitedFetch = rateLimited(fetchJson, 500);
      await limitedFetch("/endpoint"); // executes immediately
      await limitedFetch("/endpoint"); // queued, executes ≥500ms later