Whether save and load functions are configured for persistence.
Get a snapshot of current statistics and state.
Object containing usage statistics and current state
Get the current state for persistence. This is the minimal data structure needed to restore the bucket.
Optionalcount: numberOptionalcount: numberOptionalcount: numberLoad state from the configured load function. If the load function returns undefined/null, the bucket state is not modified.
Save the current state using the configured save function.
Waits for tokens to be available and consumes them atomically.
Resolves true when tokens were consumed and false when the wait
was abandoned because abortController fired — before, during, or
after the wait. An aborted caller never consumes a token.
Optionalcount: numberOptionalopts: {Waits for the next token to be available before allowing the caller to proceed.
Resolves true when a token is available and false when the wait
was abandoned because abortController fired. A false result means
no token was secured — the caller must not consume().
Optionalcount: numberOptionalopts: {
Token bucket implementation of rate limiting with optional persistence support.
Example
Example