Skip to main content
Version: 1.x

LeakyBucketAlgorithm

LeakyBucketAlgorithm

Leaky bucket algorithm for smoothing output to a steady rate.

Signature
class LeakyBucketAlgorithm implements RateLimitAlgorithm {
public readonly type: RateLimitAlgorithmType = 'leaky-bucket';
constructor(storage: RateLimitStorage, config: LeakyBucketConfig)
consume(key: string) => Promise<RateLimitResult>;
reset(key: string) => Promise<void>;
}

type

constructor

method
(storage: RateLimitStorage, config: LeakyBucketConfig) => LeakyBucketAlgorithm

Create a leaky-bucket algorithm bound to a storage backend.

consume

method
(key: string) => Promise<RateLimitResult>

Record one attempt and return the current bucket status for this key.

reset

method
(key: string) => Promise<void>

Reset the stored key state for this limiter.