/** * Token bucket rate limiter. * * Standalone utility — does not import from any other local module. */ /** * Token bucket rate limiter using a continuous-refill token bucket. * * Tokens accumulate at `tokensPerSecond` up to a maximum of `maxBurst`. * `consume()` blocks until the requested number of tokens are available, * servicing concurrent callers in FIFO order. */ export declare class TokenBucket { private readonly tokensPerSecond; private readonly maxBurst; /** Current number of available tokens (fractional allowed). */ private available; /** Timestamp (ms) of the last refill computation. */ private lastRefillTime; /** FIFO queue of consumers waiting for tokens. */ private readonly queue; /** Handle to the refill interval, or `null` when disposed. */ private intervalId; /** * @param tokensPerSecond - Rate of token refill (default: 5). * @param maxBurst - Maximum accumulated tokens (default: 10). */ constructor(tokensPerSecond?: number, maxBurst?: number); /** * Refill tokens based on elapsed wall-clock time since the last refill, * then service as many queued consumers as possible in FIFO order. */ private refill; /** * Fulfill queued consumers in FIFO order while tokens are sufficient. * A consumer whose requested `count` exceeds `maxBurst` is auto-allowed * (it would otherwise deadlock forever) and drains the bucket to zero. */ private drainQueue; /** * Wait until `count` tokens are available, then consume them. * * Resolves immediately if enough tokens are available, otherwise waits * for refill. Concurrent callers are serviced in FIFO order. * * @param count - Number of tokens to consume (default: 1). */ consume(count?: number): Promise; /** * Try to consume tokens without waiting. Returns `true` if successful, * `false` if insufficient tokens are currently available. * * @param count - Number of tokens to consume (default: 1). */ tryConsume(count?: number): boolean; /** * Get current bucket state. * * @returns An object with the current available tokens, the max burst * capacity, and the refill rate (tokens per second). */ getStats(): { available: number; maxBurst: number; rate: number; }; /** * Stop the refill timer and clean up. Any pending consumers are rejected * with an Error. Subsequent calls to `consume()` will reject and * `tryConsume()` will return `false`. */ dispose(): void; } //# sourceMappingURL=rate-limiter.d.ts.map