Skip to content
Buy me a coffee

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.

new WindowCounter(permitLimit, windowMs, segments, origin, alignment?): WindowCounter

Defined in: src/window-rate-limiter.ts:93

number

number

number

number

"fixed" | "first-request" = 'fixed'

WindowCounter

readonly permitLimit: number

Defined in: src/window-rate-limiter.ts:86

RateLimiterAlgorithm.permitLimit

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.

number

number

AcquireResult

RateLimiterAlgorithm.acquire


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.

number

number

void

RateLimiterAlgorithm.adjust


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.

WindowCounterState

number

void

RateLimiterAlgorithm.restore


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.

number

WindowCounterState

RateLimiterAlgorithm.snapshot