index.d.ts 841 B

12345678910111213141516171819202122
  1. export type TokenBucketError = string
  2. export type Fail<T> = (error: T) => void
  3. export type Success<T> = (error: null, data: T) => void
  4. export type RemoveTokensCallback = Fail<TokenBucketError> | Success<number>
  5. type Interval = number | 'second' | 'sec' | 'minute' | 'min' | 'hour' | 'hr' | 'day'
  6. export declare class TokenBucket {
  7. constructor(bucketSize: number, tokensPerInterval: number, interval: Interval, parentBucket?: TokenBucket)
  8. removeTokens(count: number, callback: RemoveTokensCallback): void
  9. tryRemoveTokens(count: number): boolean
  10. drip(): boolean
  11. }
  12. export declare class RateLimiter {
  13. constructor(tokensPerInterval: number, interval: Interval, fireImmediately?: boolean)
  14. removeTokens(count: number, callback: RemoveTokensCallback): void
  15. tryRemoveTokens(count: number): boolean
  16. getTokensRemaining(): number
  17. }