LeakyBucket
Documentation / @discordeno/utils / LeakyBucket
Class: LeakyBucket
Defined in: packages/utils/src/bucket.ts:4
Implements
Constructors
Constructor
new LeakyBucket(
options?):LeakyBucket
Defined in: packages/utils/src/bucket.ts:22
Parameters
options?
Returns
LeakyBucket
Properties
logger
logger:
Pick<typeoflogger,"debug"|"info"|"warn"|"error"|"fatal">
Defined in: packages/utils/src/bucket.ts:20
Logger used in the leaky bucket
Implementation of
max
max:
number
Defined in: packages/utils/src/bucket.ts:5
Max requests allowed at once.
Default
1
Implementation of
processing
processing:
boolean=false
Defined in: packages/utils/src/bucket.ts:14
Whether or not the queue is already processing.
queue
queue: (
value) =>void[] =[]
Defined in: packages/utils/src/bucket.ts:12
The queue of requests to acquire an available request. Mapped by <shardId, resolve()>
Parameters
value
void | PromiseLike<void>
Returns
void
refillAmount
refillAmount:
number
Defined in: packages/utils/src/bucket.ts:7
Amount of requests to refill at each interval.
Default
1
Implementation of
LeakyBucketOptions.refillAmount
refillInterval
refillInterval:
number
Defined in: packages/utils/src/bucket.ts:6
Interval in milliseconds between refills.
Default
5000
Implementation of
LeakyBucketOptions.refillInterval
refillsAt?
optionalrefillsAt:number
Defined in: packages/utils/src/bucket.ts:18
The timestamp in milliseconds when the next refill is scheduled.
timeoutId?
optionaltimeoutId:Timeout
Defined in: packages/utils/src/bucket.ts:16
The timeout id for the timer to reduce the used amount by the refill amount.
used
used:
number=0
Defined in: packages/utils/src/bucket.ts:10
The amount of requests that have been used up already.
Accessors
remaining
Get Signature
get remaining():
number
Defined in: packages/utils/src/bucket.ts:30
The amount of requests that still remain.
Returns
number
Methods
acquire()
acquire(
highPriority?):Promise<void>
Defined in: packages/utils/src/bucket.ts:106
Pauses the execution until the request is available to be made.
Parameters
highPriority?
boolean
Returns
Promise<void>
processQueue()
processQueue():
Promise<void>
Defined in: packages/utils/src/bucket.ts:54
Begin processing the queue.
Returns
Promise<void>
refillBucket()
refillBucket():
void
Defined in: packages/utils/src/bucket.ts:35
Refills the bucket as needed.
Returns
void