TokenBucketStrategy
ref / ratelimiter / TokenBucketStrategy
Implements the Token Bucket rate-limiting algorithm.
Implements
ts
ILimiterStrategy<TokenBucketState>
Constructors
ts
TokenBucketStrategy(options: TokenBucketStrategyOptions);
Constructs a new Token
.
Properties
options
ts
readonly options: TokenBucketStrategyOptions;
Methods
check
ts
check(key: string, storage: IStorageEngine): Promise<LimitResult>;
Executes the token bucket algorithm for a given request.
This method gets the user’s current state, refills their token bucket based on the elapsed time, consumes a token if available, and saves the new state back to storage.