Creates a new RateLimiter instance.
Configuration options
Attempts to acquire tokens and returns a Result with detailed information.
Number of tokens to acquire (default: 1)
Result containing void on success, or RateLimitExceeded on failure
Waits until the specified number of tokens are available, then acquires them.
Number of tokens to acquire (default: 1)
Promise that resolves when tokens are acquired
Returns the current number of available tokens. Performs a refill before returning the count.
Number of available tokens (may be fractional)
Returns the number of whole tokens available.
Integer number of available tokens
Resets the rate limiter to its initial state. The bucket is refilled to capacity.
Returns the bucket's maximum capacity.
Returns the refill rate in tokens per second.
Calculates the time in milliseconds until the specified tokens are available.
Number of tokens needed (default: 1)
Time in milliseconds until tokens are available, 0 if already available
Token bucket rate limiter for controlling request rates.
The token bucket algorithm works as follows:
Example