firefly-limiter - v1.0.1
    Preparing search index...

    Class RateLimiter

    A token bucket, in this process and no other.

    It refills against the clock rather than on a timer, so it costs nothing while idle and cannot drift. Sharing one across a fleet needs a store, a clock all the machines agree on, and an answer for what happens when the store is down, none of which this package can pick for you.

    Callers that have to wait are served in the order they arrived, so a steady stream of new calls cannot starve the one that has been waiting longest.

    Belongs outside the bulkhead: waiting for a token should not hold a concurrency slot.

    Index
    policy: Policy = ...

    Spends a token before the work starts, waiting or refusing when there is none.

    • get tokens(): number

      Tokens available now, including everything the bucket has refilled since the last call.

      Returns number

    • Spends one token, waiting for it if the limiter is set to wait.

      Parameters

      • Optionalsignal: AbortSignal

      Returns Promise<void>

      If the bucket is empty and onExhausted is "reject".