TokenBucket
Defined in: src/window-rate-limiter.ts:179
Token bucket: tokenLimit burst, tokensPerPeriod added every period ms. Tokens can go negative through adjust (penalty).
Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new TokenBucket(
tokenLimit,periodMs,tokensPerPeriod,now):TokenBucket
Defined in: src/window-rate-limiter.ts:186
Parameters
Section titled “Parameters”tokenLimit
Section titled “tokenLimit”number
periodMs
Section titled “periodMs”number
tokensPerPeriod
Section titled “tokensPerPeriod”number
number
Returns
Section titled “Returns”TokenBucket
Properties
Section titled “Properties”permitLimit
Section titled “permitLimit”
readonlypermitLimit:number
Defined in: src/window-rate-limiter.ts:180
Implementation of
Section titled “Implementation of”RateLimiterAlgorithm.permitLimit
Methods
Section titled “Methods”acquire()
Section titled “acquire()”acquire(
permits,now):AcquireResult
Defined in: src/window-rate-limiter.ts:194
Takes permits if they fit, else says how many ms until they would. permits is never above permitLimit.
Parameters
Section titled “Parameters”permits
Section titled “permits”number
number
Returns
Section titled “Returns”Implementation of
Section titled “Implementation of”adjust()
Section titled “adjust()”adjust(
points,now):void
Defined in: src/window-rate-limiter.ts:203
Charges (points > 0) or refunds (points < 0) permits without admission check: penalty / reward. Optional.
Parameters
Section titled “Parameters”points
Section titled “points”number
number
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”restore()
Section titled “restore()”restore(
state,now):void
Defined in: src/window-rate-limiter.ts:213
Loads a snapshot, aging it by the time passed since it was taken. Optional.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”snapshot()
Section titled “snapshot()”snapshot(
now):TokenBucketState
Defined in: src/window-rate-limiter.ts:208
JSON-serializable state as of now, for restore (e.g. after a restart). Optional.
Parameters
Section titled “Parameters”number