Amazon Vinyl
    Preparing search index...

    Function rateLimit

    • Rate-limits invocations with a token bucket. The bucket holds up to RateLimitOptions.capacity tokens and refills one token every RateLimitOptions.interval seconds. Each call consumes a token and runs immediately; a call made while the bucket is empty is queued and invoked as tokens refill (in call order).

      Unlike throttle, which drops calls that arrive within its window, rateLimit never drops a call — it only delays the ones that exceed the rate. A full bucket allows an initial burst of capacity calls.

      Parameters

      • inner: () => void

        The function to invoke at the limited rate.

      • options: RateLimitOptions

        The bucket capacity (max burst) and refill interval.

      Returns RateLimitedCallback

      A callback that queues-and-limits invocations of inner, with reset and dispose handles. dispose cancels any queued calls and prevents further invocation.