biofriction-wp-theme/node_modules/limiter/index.d.ts

23 lines
863 B
TypeScript
Raw Normal View History

2021-10-26 14:18:09 +02:00
export type TokenBucketError = string
export type Fail<T> = (error: T) => void
export type Success<T> = (error: null, data: T) => void
export type RemoveTokensCallback = Fail<TokenBucketError> | Success<number>
type Interval = number | 'second' | 'sec' | 'minute' | 'min' | 'hour' | 'hr' | 'day'
export declare class TokenBucket {
constructor(bucketSize: number, tokensPerInterval: number, interval: Interval, parentBucket?: TokenBucket)
removeTokens(count: number, callback: RemoveTokensCallback): void
tryRemoveTokens(count: number): boolean
drip(): boolean
}
export declare class RateLimiter {
constructor(tokensPerInterval: number, interval: Interval, fireImmediately?: boolean)
removeTokens(count: number, callback: RemoveTokensCallback): void
tryRemoveTokens(count: number): boolean
getTokensRemaining(): number
}