MCPcopy
hub / github.com/sindresorhus/p-queue / assertSlidingWindow

Function assertSlidingWindow

test/strict.ts:6–13  ·  view source on GitHub ↗
(executionTimes: number[], interval: number, intervalCap: number, jitterMilliseconds = Math.min(25, Math.trunc(interval * 0.2)))

Source from the content-addressed store, hash-verified

4import PQueue from '../source/index.js';
5
6const assertSlidingWindow = (executionTimes: number[], interval: number, intervalCap: number, jitterMilliseconds = Math.min(25, Math.trunc(interval * 0.2))) => {
7 const minimumInterval = Math.max(0, interval - jitterMilliseconds);
8
9 for (let index = intervalCap; index < executionTimes.length; index++) {
10 const delta = executionTimes[index] - executionTimes[index - intervalCap];
11 assert.ok(delta >= minimumInterval, `Task ${index} violated sliding window: ${delta}ms < ${minimumInterval}ms`);
12 }
13};
14
15test('strict mode enforces sliding window rate limiting', async () => {
16 const queue = new PQueue({

Callers 1

strict.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…