WindowCounter
Defined in: src/window-rate-limiter.ts:85
Segmented sliding window: the window is split into segments buckets and slides one bucket at a time.
With 1 segment it is a fixed window. Windows are aligned to origin; with 'first-request' alignment a new
window starts at the first request after the window empties instead.
Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new WindowCounter(
permitLimit,windowMs,segments,origin,alignment?):WindowCounter
Defined in: src/window-rate-limiter.ts:93
Parameters
Section titled “Parameters”permitLimit
Section titled “permitLimit”number
windowMs
Section titled “windowMs”number
segments
Section titled “segments”number
origin
Section titled “origin”number
alignment?
Section titled “alignment?”"fixed" | "first-request" = 'fixed'
Returns
Section titled “Returns”WindowCounter
Properties
Section titled “Properties”permitLimit
Section titled “permitLimit”
readonlypermitLimit:number
Defined in: src/window-rate-limiter.ts:86
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:125
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:145
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:113
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):WindowCounterState
Defined in: src/window-rate-limiter.ts:101
JSON-serializable state as of now, for restore (e.g. after a restart). Optional.
Parameters
Section titled “Parameters”number