adaptive-concurrency 0.3.4 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/dist/index.d.ts +1 -2
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +1 -2
  4. package/dist/limiter/allocation-unavailable-strategies/BlockingBacklogRejection.d.ts +15 -12
  5. package/dist/limiter/allocation-unavailable-strategies/BlockingBacklogRejection.d.ts.map +1 -1
  6. package/dist/limiter/allocation-unavailable-strategies/BlockingBacklogRejection.js +8 -6
  7. package/dist/limiter/allocation-unavailable-strategies/DelayedRejectStrategy.d.ts +1 -1
  8. package/dist/limiter/allocation-unavailable-strategies/DelayedRejectStrategy.js +1 -1
  9. package/dist/limiter/factories/makeBlockingLimiter.d.ts +1 -2
  10. package/dist/limiter/factories/makeBlockingLimiter.d.ts.map +1 -1
  11. package/dist/limiter/factories/makeBlockingLimiter.js +7 -5
  12. package/dist/limiter/factories/makeLifoBlockingLimiter.d.ts +2 -3
  13. package/dist/limiter/factories/makeLifoBlockingLimiter.d.ts.map +1 -1
  14. package/dist/limiter/factories/makeLifoBlockingLimiter.js +6 -4
  15. package/dist/limiter/factories/makePartitionedBlockingLimiter.d.ts +2 -3
  16. package/dist/limiter/factories/makePartitionedBlockingLimiter.d.ts.map +1 -1
  17. package/dist/limiter/factories/makePartitionedBlockingLimiter.js +6 -4
  18. package/dist/limiter/factories/makePartitionedLifoBlockingLimiter.d.ts +1 -2
  19. package/dist/limiter/factories/makePartitionedLifoBlockingLimiter.d.ts.map +1 -1
  20. package/dist/limiter/factories/makePartitionedLifoBlockingLimiter.js +8 -6
  21. package/dist/utils/LinkedWaiterQueue.d.ts +13 -9
  22. package/dist/utils/LinkedWaiterQueue.d.ts.map +1 -1
  23. package/dist/utils/LinkedWaiterQueue.js +16 -12
  24. package/dist/utils/index.d.ts +0 -1
  25. package/dist/utils/index.d.ts.map +1 -1
  26. package/dist/utils/index.js +0 -1
  27. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -21,8 +21,7 @@ export { squareRoot, squareRootWithBaseline } from "./utils/index.js";
21
21
  export * from "./limiter/factories/index.js";
22
22
  export { PartitionedStrategy, type PartitionConfig, } from "./limiter/acquire-strategies/PartitionedStrategy.js";
23
23
  export { SemaphoreStrategy } from "./limiter/acquire-strategies/SemaphoreStrategy.js";
24
+ export { BlockingBacklogRejection, MAX_TIMEOUT, type BlockingBacklogRejectionOptions, type WaiterQueue, } from "./limiter/allocation-unavailable-strategies/BlockingBacklogRejection.js";
24
25
  export { DelayedRejectStrategy, type DelayedRejectStrategyOptions, } from "./limiter/allocation-unavailable-strategies/DelayedRejectStrategy.js";
25
26
  export { DelayedThenBlockingRejection } from "./limiter/allocation-unavailable-strategies/DelayedThenBlockingRejection.js";
26
- export { FifoBlockingRejection } from "./limiter/allocation-unavailable-strategies/FifoBlockingRejection.js";
27
- export { LifoBlockingRejection, type LifoBlockingRejectionOptions, } from "./limiter/allocation-unavailable-strategies/LifoBlockingRejection.js";
28
27
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,YAAY,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EACL,OAAO,EACP,WAAW,EACX,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,4BAA4B,EACjC,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,eAAe,GACrB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EACL,SAAS,EACT,kBAAkB,EAClB,KAAK,OAAO,EACZ,KAAK,kBAAkB,EACvB,KAAK,WAAW,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AAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,EACL,UAAU,EACV,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,GACtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,aAAa,EACb,KAAK,oBAAoB,GAC1B,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,YAAY,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAG7E,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAChF,OAAO,EAAE,4BAA4B,EAAE,MAAM,0CAA0C,CAAC;AACxF,YAAY,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAGnE,OAAO,EAAE,UAAU,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAEtE,cAAc,8BAA8B,CAAC;AAG7C,OAAO,EACL,mBAAmB,EACnB,KAAK,eAAe,GACrB,MAAM,qDAAqD,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,mDAAmD,CAAC;AAGtF,OAAO,EACL,wBAAwB,EACxB,WAAW,EACX,KAAK,+BAA+B,EACpC,KAAK,WAAW,GACjB,MAAM,yEAAyE,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,KAAK,4BAA4B,GAClC,MAAM,sEAAsE,CAAC;AAC9E,OAAO,EAAE,4BAA4B,EAAE,MAAM,6EAA6E,CAAC"}
package/dist/index.js CHANGED
@@ -23,7 +23,6 @@ export * from "./limiter/factories/index.js";
23
23
  export { PartitionedStrategy, } from "./limiter/acquire-strategies/PartitionedStrategy.js";
24
24
  export { SemaphoreStrategy } from "./limiter/acquire-strategies/SemaphoreStrategy.js";
25
25
  // Rejection strategies
26
+ export { BlockingBacklogRejection, MAX_TIMEOUT, } from "./limiter/allocation-unavailable-strategies/BlockingBacklogRejection.js";
26
27
  export { DelayedRejectStrategy, } from "./limiter/allocation-unavailable-strategies/DelayedRejectStrategy.js";
27
28
  export { DelayedThenBlockingRejection } from "./limiter/allocation-unavailable-strategies/DelayedThenBlockingRejection.js";
28
- export { FifoBlockingRejection } from "./limiter/allocation-unavailable-strategies/FifoBlockingRejection.js";
29
- export { LifoBlockingRejection, } from "./limiter/allocation-unavailable-strategies/LifoBlockingRejection.js";
@@ -1,36 +1,39 @@
1
1
  import type { LimitAllotment } from "../../LimitAllotment.js";
2
2
  import type { AcquireResult, AllotmentUnavailableStrategy } from "../../Limiter.js";
3
- import type { WaiterHandle } from "../../utils/LinkedWaiterQueue.js";
4
- type Waiter<ContextT> = {
3
+ export type Waiter<ContextT> = {
5
4
  context: ContextT;
6
5
  retry: (context: ContextT) => AcquireResult;
7
- handle: WaiterHandle;
8
6
  resolve: (allotment: LimitAllotment | undefined) => void;
9
7
  };
10
8
  export declare const MAX_TIMEOUT: number;
11
- export type BlockingBacklogRejectionOptions<ContextT> = {
9
+ export type BlockingBacklogRejectionOptions<ContextT, Handle> = {
12
10
  backlogSize: number;
13
11
  backlogTimeout: number | ((context: ContextT) => number);
14
- queue: WaiterQueue<Waiter<ContextT>>;
12
+ queue: WaiterQueue<ContextT, Handle>;
15
13
  };
16
- export type WaiterQueue<WaiterT extends Waiter<any>> = {
17
- enqueue: (waiter: Omit<WaiterT, "handle">) => WaiterT;
18
- peekHead: () => WaiterT | undefined;
19
- removeByHandle: (handle: WaiterHandle) => boolean;
14
+ export type WaiterQueue<ContextT, Handle> = {
15
+ enqueue: (waiter: Waiter<ContextT>) => {
16
+ value: Waiter<ContextT>;
17
+ handle: Handle;
18
+ };
19
+ peekHead: () => {
20
+ value: Waiter<ContextT>;
21
+ handle: Handle;
22
+ } | undefined;
23
+ removeByHandle: (handle: Handle) => boolean;
20
24
  size: () => number;
21
25
  };
22
- export declare class BlockingBacklogRejection<ContextT> implements AllotmentUnavailableStrategy<ContextT> {
26
+ export declare class BlockingBacklogRejection<ContextT, Handle> implements AllotmentUnavailableStrategy<ContextT> {
23
27
  private readonly backlogSize;
24
28
  private readonly getBacklogTimeout;
25
29
  private readonly queue;
26
30
  private drainInProgress;
27
31
  private releaseDuringDrain;
28
- constructor(options: BlockingBacklogRejectionOptions<ContextT>);
32
+ constructor(options: BlockingBacklogRejectionOptions<ContextT, Handle>);
29
33
  onAllotmentUnavailable(context: ContextT, retry: (context: ContextT) => AcquireResult, signal?: AbortSignal): Promise<LimitAllotment | undefined>;
30
34
  onAllotmentReleased(): Promise<void>;
31
35
  onLimitChanged(oldLimit: number, newLimit: number): void;
32
36
  private waitInBacklog;
33
37
  private assertTimeoutWithinBounds;
34
38
  }
35
- export {};
36
39
  //# sourceMappingURL=BlockingBacklogRejection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"BlockingBacklogRejection.d.ts","sourceRoot":"","sources":["../../../src/limiter/allocation-unavailable-strategies/BlockingBacklogRejection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,KAAK,EACV,aAAa,EACb,4BAA4B,EAC7B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAErE,KAAK,MAAM,CAAC,QAAQ,IAAI;IACtB,OAAO,EAAE,QAAQ,CAAC;IAClB,KAAK,EAAE,CAAC,OAAO,EAAE,QAAQ,KAAK,aAAa,CAAC;IAC5C,MAAM,EAAE,YAAY,CAAC;IACrB,OAAO,EAAE,CAAC,SAAS,EAAE,cAAc,GAAG,SAAS,KAAK,IAAI,CAAC;CAC1D,CAAC;AAEF,eAAO,MAAM,WAAW,QAAiB,CAAC;AAE1C,MAAM,MAAM,+BAA+B,CAAC,QAAQ,IAAI;IACtD,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,GAAG,CAAC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OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAgC;IAClE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgC;IACtD,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,kBAAkB,CAAS;gBAEvB,OAAO,EAAE,+BAA+B,CAAC,QAAQ,EAAE,MAAM,CAAC;IA6BtE,sBAAsB,CACpB,OAAO,EAAE,QAAQ,EACjB,KAAK,EAAE,CAAC,OAAO,EAAE,QAAQ,KAAK,aAAa,EAC3C,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC;IAYhC,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IA6C1C,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IAQxD,OAAO,CAAC,aAAa;IAkCrB,OAAO,CAAC,yBAAyB;CAUlC"}
@@ -45,10 +45,11 @@ export class BlockingBacklogRejection {
45
45
  this.drainInProgress = true;
46
46
  try {
47
47
  while (this.queue.size() > 0) {
48
- const waiter = this.queue.peekHead();
49
- if (!waiter) {
48
+ const queuedWaiter = this.queue.peekHead();
49
+ if (!queuedWaiter) {
50
50
  return;
51
51
  }
52
+ const waiter = queuedWaiter.value;
52
53
  this.releaseDuringDrain = false;
53
54
  const allotment = await waiter.retry(waiter.context);
54
55
  if (!allotment) {
@@ -60,7 +61,7 @@ export class BlockingBacklogRejection {
60
61
  }
61
62
  return;
62
63
  }
63
- if (!this.queue.removeByHandle(waiter.handle)) {
64
+ if (!this.queue.removeByHandle(queuedWaiter.handle)) {
64
65
  // Waiter expired while retry was in-flight. Release the acquired slot
65
66
  // so future retries can serve active queued waiters.
66
67
  await allotment.releaseAndIgnore();
@@ -91,17 +92,18 @@ export class BlockingBacklogRejection {
91
92
  cleanup();
92
93
  resolve(allotment);
93
94
  };
94
- const waiter = this.queue.enqueue({
95
+ const waiter = {
95
96
  context,
96
97
  retry,
97
98
  resolve: (allotment) => settle(allotment),
98
- });
99
+ };
100
+ const { handle } = this.queue.enqueue(waiter);
99
101
  const timer = setTimeout(() => settle(undefined), timeout);
100
102
  const onAbort = () => settle(undefined);
101
103
  const cleanup = () => {
102
104
  clearTimeout(timer);
103
105
  signal?.removeEventListener("abort", onAbort);
104
- this.queue.removeByHandle(waiter.handle);
106
+ this.queue.removeByHandle(handle);
105
107
  };
106
108
  signal?.addEventListener("abort", onAbort, { once: true });
107
109
  });
@@ -16,7 +16,7 @@ export interface DelayedRejectStrategyOptions<ContextT> {
16
16
  /**
17
17
  * When the acquire strategy rejects, waits up to `delayMsForContext(context)`,
18
18
  * then still returns no allotment. This adds a form of backpressure. Does not
19
- * call `retry` — unlike {@link FifoBlockingRejection}, this is "delay then
19
+ * call `retry` — unlike {@link BlockingBacklogRejection}, this is "delay then
20
20
  * reject," not "wait for capacity." Compose with `PartitionedStrategy` via
21
21
  * `Limiter.rejectionStrategy`; partition delays are not fields on `PartitionConfig`.
22
22
  */
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * When the acquire strategy rejects, waits up to `delayMsForContext(context)`,
3
3
  * then still returns no allotment. This adds a form of backpressure. Does not
4
- * call `retry` — unlike {@link FifoBlockingRejection}, this is "delay then
4
+ * call `retry` — unlike {@link BlockingBacklogRejection}, this is "delay then
5
5
  * reject," not "wait for capacity." Compose with `PartitionedStrategy` via
6
6
  * `Limiter.rejectionStrategy`; partition delays are not fields on `PartitionConfig`.
7
7
  */
@@ -1,8 +1,7 @@
1
1
  import { Limiter, type LimiterOptions } from "../../Limiter.js";
2
- import { type FifoBlockingRejectionOptions } from "../allocation-unavailable-strategies/FifoBlockingRejection.js";
3
2
  export declare function makeBlockingLimiter<ContextT = void>(options?: {
4
3
  backlogSize?: number;
5
- backlogTimeout?: FifoBlockingRejectionOptions<ContextT>["backlogTimeout"];
4
+ backlogTimeout?: number | ((context: ContextT) => number);
6
5
  limiter?: Omit<LimiterOptions<ContextT>, "allotmentUnavailableStrategy">;
7
6
  }): Limiter<ContextT>;
8
7
  //# sourceMappingURL=makeBlockingLimiter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"makeBlockingLimiter.d.ts","sourceRoot":"","sources":["../../../src/limiter/factories/makeBlockingLimiter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,KAAK,cAAc,EACpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAEL,KAAK,4BAA4B,EAClC,MAAM,+DAA+D,CAAC;AAEvE,wBAAgB,mBAAmB,CAAC,QAAQ,GAAG,IAAI,EACjD,OAAO,GAAE;IACP,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,4BAA4B,CAAC,QAAQ,CAAC,CAAC,gBAAgB,CAAC,CAAC;IAC1E,OAAO,CAAC,EAAE,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,8BAA8B,CAAC,CAAC;CACrE,GACL,OAAO,CAAC,QAAQ,CAAC,CAQnB"}
1
+ {"version":3,"file":"makeBlockingLimiter.d.ts","sourceRoot":"","sources":["../../../src/limiter/factories/makeBlockingLimiter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAQhE,wBAAgB,mBAAmB,CAAC,QAAQ,GAAG,IAAI,EACjD,OAAO,GAAE;IACP,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,OAAO,EAAE,QAAQ,KAAK,MAAM,CAAC,CAAC;IAC1D,OAAO,CAAC,EAAE,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,8BAA8B,CAAC,CAAC;CACrE,GACL,OAAO,CAAC,QAAQ,CAAC,CASnB"}
@@ -1,11 +1,13 @@
1
- import { Limiter, } from "../../Limiter.js";
2
- import { FifoBlockingRejection, } from "../allocation-unavailable-strategies/FifoBlockingRejection.js";
1
+ import { Limiter } from "../../Limiter.js";
2
+ import { LinkedWaiterQueue } from "../../utils/LinkedWaiterQueue.js";
3
+ import { BlockingBacklogRejection, MAX_TIMEOUT, } from "../allocation-unavailable-strategies/BlockingBacklogRejection.js";
3
4
  export function makeBlockingLimiter(options = {}) {
4
5
  return new Limiter({
5
6
  ...options.limiter,
6
- allotmentUnavailableStrategy: new FifoBlockingRejection({
7
- backlogSize: options.backlogSize,
8
- backlogTimeout: options.backlogTimeout,
7
+ allotmentUnavailableStrategy: new BlockingBacklogRejection({
8
+ backlogSize: options.backlogSize ?? Number.POSITIVE_INFINITY,
9
+ backlogTimeout: options.backlogTimeout ?? MAX_TIMEOUT,
10
+ queue: new LinkedWaiterQueue("back"),
9
11
  }),
10
12
  });
11
13
  }
@@ -1,8 +1,7 @@
1
1
  import { Limiter, type LimiterOptions } from "../../Limiter.js";
2
- import { type LifoBlockingRejectionOptions } from "../allocation-unavailable-strategies/LifoBlockingRejection.js";
3
2
  export declare function makeLifoBlockingLimiter<ContextT = void>(options?: {
4
- backlogSize?: LifoBlockingRejectionOptions<ContextT>["backlogSize"];
5
- backlogTimeout?: LifoBlockingRejectionOptions<ContextT>["backlogTimeout"];
3
+ backlogSize?: number;
4
+ backlogTimeout?: number | ((context: ContextT) => number);
6
5
  limiter?: Omit<LimiterOptions<ContextT>, "allotmentUnavailableStrategy">;
7
6
  }): Limiter<ContextT>;
8
7
  //# sourceMappingURL=makeLifoBlockingLimiter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"makeLifoBlockingLimiter.d.ts","sourceRoot":"","sources":["../../../src/limiter/factories/makeLifoBlockingLimiter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAEL,KAAK,4BAA4B,EAClC,MAAM,+DAA+D,CAAC;AAEvE,wBAAgB,uBAAuB,CAAC,QAAQ,GAAG,IAAI,EACrD,OAAO,GAAE;IACP,WAAW,CAAC,EAAE,4BAA4B,CAAC,QAAQ,CAAC,CAAC,aAAa,CAAC,CAAC;IACpE,cAAc,CAAC,EAAE,4BAA4B,CAAC,QAAQ,CAAC,CAAC,gBAAgB,CAAC,CAAC;IAC1E,OAAO,CAAC,EAAE,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,8BAA8B,CAAC,CAAC;CACrE,GACL,OAAO,CAAC,QAAQ,CAAC,CAQnB"}
1
+ {"version":3,"file":"makeLifoBlockingLimiter.d.ts","sourceRoot":"","sources":["../../../src/limiter/factories/makeLifoBlockingLimiter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAOhE,wBAAgB,uBAAuB,CAAC,QAAQ,GAAG,IAAI,EACrD,OAAO,GAAE;IACP,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,OAAO,EAAE,QAAQ,KAAK,MAAM,CAAC,CAAC;IAC1D,OAAO,CAAC,EAAE,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,8BAA8B,CAAC,CAAC;CACrE,GACL,OAAO,CAAC,QAAQ,CAAC,CASnB"}
@@ -1,11 +1,13 @@
1
1
  import { Limiter } from "../../Limiter.js";
2
- import { LifoBlockingRejection, } from "../allocation-unavailable-strategies/LifoBlockingRejection.js";
2
+ import { LinkedWaiterQueue } from "../../utils/LinkedWaiterQueue.js";
3
+ import { BlockingBacklogRejection, } from "../allocation-unavailable-strategies/BlockingBacklogRejection.js";
3
4
  export function makeLifoBlockingLimiter(options = {}) {
4
5
  return new Limiter({
5
6
  ...options.limiter,
6
- allotmentUnavailableStrategy: new LifoBlockingRejection({
7
- backlogSize: options.backlogSize,
8
- backlogTimeout: options.backlogTimeout,
7
+ allotmentUnavailableStrategy: new BlockingBacklogRejection({
8
+ backlogSize: options.backlogSize ?? 100,
9
+ backlogTimeout: options.backlogTimeout ?? 1_000,
10
+ queue: new LinkedWaiterQueue("front"),
9
11
  }),
10
12
  });
11
13
  }
@@ -1,6 +1,5 @@
1
1
  import { Limiter, type LimiterOptions } from "../../Limiter.js";
2
2
  import { type PartitionConfig } from "../acquire-strategies/PartitionedStrategy.js";
3
- import { type FifoBlockingRejectionOptions } from "../allocation-unavailable-strategies/FifoBlockingRejection.js";
4
3
  export declare function makePartitionedBlockingLimiter<ContextT, PartitionName extends string = string>(options: {
5
4
  partitionResolver: (context: ContextT) => PartitionName | undefined;
6
5
  partitions: Record<PartitionName, PartitionConfig & {
@@ -8,7 +7,7 @@ export declare function makePartitionedBlockingLimiter<ContextT, PartitionName e
8
7
  }>;
9
8
  limiter?: Omit<LimiterOptions<ContextT>, "acquireStrategy">;
10
9
  maxConcurrentDelays?: number;
11
- backlogSize?: FifoBlockingRejectionOptions<ContextT>["backlogSize"];
12
- backlogTimeout?: FifoBlockingRejectionOptions<ContextT>["backlogTimeout"];
10
+ backlogSize?: number;
11
+ backlogTimeout?: number | ((context: ContextT) => number);
13
12
  }): Limiter<ContextT>;
14
13
  //# sourceMappingURL=makePartitionedBlockingLimiter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"makePartitionedBlockingLimiter.d.ts","sourceRoot":"","sources":["../../../src/limiter/factories/makePartitionedBlockingLimiter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAEL,KAAK,eAAe,EACrB,MAAM,8CAA8C,CAAC;AAGtD,OAAO,EAEL,KAAK,4BAA4B,EAClC,MAAM,+DAA+D,CAAC;AAEvE,wBAAgB,8BAA8B,CAC5C,QAAQ,EACR,aAAa,SAAS,MAAM,GAAG,MAAM,EACrC,OAAO,EAAE;IACT,iBAAiB,EAAE,CAAC,OAAO,EAAE,QAAQ,KAAK,aAAa,GAAG,SAAS,CAAC;IACpE,UAAU,EAAE,MAAM,CAAC,aAAa,EAAE,eAAe,GAAG;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC1E,OAAO,CAAC,EAAE,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,iBAAiB,CAAC,CAAC;IAC5D,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,WAAW,CAAC,EAAE,4BAA4B,CAAC,QAAQ,CAAC,CAAC,aAAa,CAAC,CAAC;IACpE,cAAc,CAAC,EAAE,4BAA4B,CAAC,QAAQ,CAAC,CAAC,gBAAgB,CAAC,CAAC;CAC3E,GAAG,OAAO,CAAC,QAAQ,CAAC,CAiCpB"}
1
+ {"version":3,"file":"makePartitionedBlockingLimiter.d.ts","sourceRoot":"","sources":["../../../src/limiter/factories/makePartitionedBlockingLimiter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEhE,OAAO,EAEL,KAAK,eAAe,EACrB,MAAM,8CAA8C,CAAC;AAStD,wBAAgB,8BAA8B,CAC5C,QAAQ,EACR,aAAa,SAAS,MAAM,GAAG,MAAM,EACrC,OAAO,EAAE;IACT,iBAAiB,EAAE,CAAC,OAAO,EAAE,QAAQ,KAAK,aAAa,GAAG,SAAS,CAAC;IACpE,UAAU,EAAE,MAAM,CAAC,aAAa,EAAE,eAAe,GAAG;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC1E,OAAO,CAAC,EAAE,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,iBAAiB,CAAC,CAAC;IAC5D,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,OAAO,EAAE,QAAQ,KAAK,MAAM,CAAC,CAAC;CAC3D,GAAG,OAAO,CAAC,QAAQ,CAAC,CAkCpB"}
@@ -1,8 +1,9 @@
1
1
  import { Limiter } from "../../Limiter.js";
2
+ import { LinkedWaiterQueue } from "../../utils/LinkedWaiterQueue.js";
2
3
  import { PartitionedStrategy, } from "../acquire-strategies/PartitionedStrategy.js";
4
+ import { BlockingBacklogRejection, MAX_TIMEOUT, } from "../allocation-unavailable-strategies/BlockingBacklogRejection.js";
3
5
  import { DelayedRejectStrategy } from "../allocation-unavailable-strategies/DelayedRejectStrategy.js";
4
6
  import { DelayedThenBlockingRejection } from "../allocation-unavailable-strategies/DelayedThenBlockingRejection.js";
5
- import { FifoBlockingRejection, } from "../allocation-unavailable-strategies/FifoBlockingRejection.js";
6
7
  export function makePartitionedBlockingLimiter(options) {
7
8
  const limit = options.limiter?.limit ?? Limiter.makeDefaultLimit();
8
9
  const delayByPartition = new Map(Object.entries(options.partitions).map(([name, cfg]) => [
@@ -28,9 +29,10 @@ export function makePartitionedBlockingLimiter(options) {
28
29
  },
29
30
  maxConcurrentDelays: options.maxConcurrentDelays,
30
31
  }),
31
- blockingStrategy: new FifoBlockingRejection({
32
- backlogSize: options.backlogSize,
33
- backlogTimeout: options.backlogTimeout,
32
+ blockingStrategy: new BlockingBacklogRejection({
33
+ backlogSize: options.backlogSize ?? Number.POSITIVE_INFINITY,
34
+ backlogTimeout: options.backlogTimeout ?? MAX_TIMEOUT,
35
+ queue: new LinkedWaiterQueue("back"),
34
36
  }),
35
37
  }),
36
38
  });
@@ -1,5 +1,4 @@
1
1
  import { Limiter, type LimiterOptions } from "../../Limiter.js";
2
- import { type LifoBlockingRejectionOptions } from "../allocation-unavailable-strategies/LifoBlockingRejection.js";
3
2
  import { type PartitionConfig } from "../acquire-strategies/PartitionedStrategy.js";
4
3
  export declare function makePartitionedLifoBlockingLimiter<ContextT, PartitionName extends string = string>(options: {
5
4
  partitionResolver: (context: ContextT) => PartitionName | undefined;
@@ -9,6 +8,6 @@ export declare function makePartitionedLifoBlockingLimiter<ContextT, PartitionNa
9
8
  limiter?: Omit<LimiterOptions<ContextT>, "acquireStrategy">;
10
9
  maxConcurrentDelays?: number;
11
10
  backlogSize?: number;
12
- backlogTimeout?: LifoBlockingRejectionOptions<ContextT>["backlogTimeout"];
11
+ backlogTimeout?: number | ((context: ContextT) => number);
13
12
  }): Limiter<ContextT>;
14
13
  //# sourceMappingURL=makePartitionedLifoBlockingLimiter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"makePartitionedLifoBlockingLimiter.d.ts","sourceRoot":"","sources":["../../../src/limiter/factories/makePartitionedLifoBlockingLimiter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,KAAK,cAAc,EACpB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAEL,KAAK,4BAA4B,EAClC,MAAM,+DAA+D,CAAC;AACvE,OAAO,EAEL,KAAK,eAAe,EACrB,MAAM,8CAA8C,CAAC;AAEtD,wBAAgB,kCAAkC,CAChD,QAAQ,EACR,aAAa,SAAS,MAAM,GAAG,MAAM,EACrC,OAAO,EAAE;IACT,iBAAiB,EAAE,CAAC,OAAO,EAAE,QAAQ,KAAK,aAAa,GAAG,SAAS,CAAC;IACpE,UAAU,EAAE,MAAM,CAAC,aAAa,EAAE,eAAe,GAAG;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC1E,OAAO,CAAC,EAAE,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,iBAAiB,CAAC,CAAC;IAC5D,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,4BAA4B,CAAC,QAAQ,CAAC,CAAC,gBAAgB,CAAC,CAAC;CAC3E,GAAG,OAAO,CAAC,QAAQ,CAAC,CAkCpB"}
1
+ {"version":3,"file":"makePartitionedLifoBlockingLimiter.d.ts","sourceRoot":"","sources":["../../../src/limiter/factories/makePartitionedLifoBlockingLimiter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEhE,OAAO,EAEL,KAAK,eAAe,EACrB,MAAM,8CAA8C,CAAC;AAQtD,wBAAgB,kCAAkC,CAChD,QAAQ,EACR,aAAa,SAAS,MAAM,GAAG,MAAM,EACrC,OAAO,EAAE;IACT,iBAAiB,EAAE,CAAC,OAAO,EAAE,QAAQ,KAAK,aAAa,GAAG,SAAS,CAAC;IACpE,UAAU,EAAE,MAAM,CAAC,aAAa,EAAE,eAAe,GAAG;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC1E,OAAO,CAAC,EAAE,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,iBAAiB,CAAC,CAAC;IAC5D,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,OAAO,EAAE,QAAQ,KAAK,MAAM,CAAC,CAAC;CAC3D,GAAG,OAAO,CAAC,QAAQ,CAAC,CAmCpB"}
@@ -1,8 +1,9 @@
1
- import { Limiter, } from "../../Limiter.js";
1
+ import { Limiter } from "../../Limiter.js";
2
+ import { LinkedWaiterQueue } from "../../utils/LinkedWaiterQueue.js";
3
+ import { PartitionedStrategy, } from "../acquire-strategies/PartitionedStrategy.js";
4
+ import { BlockingBacklogRejection, } from "../allocation-unavailable-strategies/BlockingBacklogRejection.js";
2
5
  import { DelayedRejectStrategy } from "../allocation-unavailable-strategies/DelayedRejectStrategy.js";
3
6
  import { DelayedThenBlockingRejection } from "../allocation-unavailable-strategies/DelayedThenBlockingRejection.js";
4
- import { LifoBlockingRejection, } from "../allocation-unavailable-strategies/LifoBlockingRejection.js";
5
- import { PartitionedStrategy, } from "../acquire-strategies/PartitionedStrategy.js";
6
7
  export function makePartitionedLifoBlockingLimiter(options) {
7
8
  const limit = options.limiter?.limit ?? Limiter.makeDefaultLimit();
8
9
  const delayByPartition = new Map(Object.entries(options.partitions).map(([name, cfg]) => [
@@ -28,9 +29,10 @@ export function makePartitionedLifoBlockingLimiter(options) {
28
29
  },
29
30
  maxConcurrentDelays: options.maxConcurrentDelays,
30
31
  }),
31
- blockingStrategy: new LifoBlockingRejection({
32
- backlogSize: options.backlogSize,
33
- backlogTimeout: options.backlogTimeout,
32
+ blockingStrategy: new BlockingBacklogRejection({
33
+ backlogSize: options.backlogSize ?? 100,
34
+ backlogTimeout: options.backlogTimeout ?? 1_000,
35
+ queue: new LinkedWaiterQueue("front"),
34
36
  }),
35
37
  }),
36
38
  });
@@ -1,21 +1,25 @@
1
- export type WaiterHandle = {
2
- key: symbol;
3
- };
1
+ declare class ItemHandle {
2
+ }
4
3
  export type EnqueueDirection = "front" | "back";
5
- export declare class LinkedWaiterQueue<WaiterT extends {
6
- handle: WaiterHandle;
7
- }> {
4
+ export declare class LinkedWaiterQueue<T extends object> {
8
5
  private head;
9
6
  private tail;
10
7
  private readonly nodes;
11
8
  private readonly enqueueDirection;
12
9
  private length;
13
10
  constructor(enqueueDirection: EnqueueDirection);
14
- enqueue(waiterWithoutHandle: Omit<WaiterT, "handle">, enqueueDirection?: EnqueueDirection): WaiterT;
15
- peekHead(): WaiterT | undefined;
16
- removeByHandle(handle: WaiterHandle): boolean;
11
+ enqueue(value: T, enqueueDirection?: EnqueueDirection): {
12
+ value: T;
13
+ handle: ItemHandle;
14
+ };
15
+ peekHead(): {
16
+ value: T;
17
+ handle: ItemHandle;
18
+ } | undefined;
19
+ removeByHandle(handle: ItemHandle): boolean;
17
20
  size(): number;
18
21
  private pushFront;
19
22
  private pushBack;
20
23
  }
24
+ export {};
21
25
  //# sourceMappingURL=LinkedWaiterQueue.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"LinkedWaiterQueue.d.ts","sourceRoot":"","sources":["../../src/utils/LinkedWaiterQueue.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IACzB,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,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AK,EAAE,CAAC,CAAC;QAAC,MAAM,EAAE,UAAU,CAAA;KAAE,GAAG,SAAS;IAUxD,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO;IAuB3C,IAAI,IAAI,MAAM;IAId,OAAO,CAAC,SAAS;IAYjB,OAAO,CAAC,QAAQ;CAWjB"}
@@ -1,3 +1,5 @@
1
+ class ItemHandle {
2
+ }
1
3
  export class LinkedWaiterQueue {
2
4
  head;
3
5
  tail;
@@ -7,20 +9,16 @@ export class LinkedWaiterQueue {
7
9
  constructor(enqueueDirection) {
8
10
  this.enqueueDirection = enqueueDirection;
9
11
  }
10
- enqueue(waiterWithoutHandle, enqueueDirection) {
11
- const handle = { key: Symbol("waiter-node") };
12
- const waiter = {
13
- ...waiterWithoutHandle,
14
- handle,
15
- };
12
+ enqueue(value, enqueueDirection) {
13
+ const handle = new ItemHandle();
16
14
  const node = {
17
15
  handle,
18
- value: waiter,
16
+ value: value,
19
17
  prev: undefined,
20
18
  next: undefined,
21
19
  };
22
20
  const direction = enqueueDirection ?? this.enqueueDirection;
23
- this.nodes.set(handle.key, node);
21
+ this.nodes.set(handle, node);
24
22
  if (direction === "front") {
25
23
  this.pushFront(node);
26
24
  }
@@ -28,16 +26,22 @@ export class LinkedWaiterQueue {
28
26
  this.pushBack(node);
29
27
  }
30
28
  this.length += 1;
31
- return waiter;
29
+ return { value, handle };
32
30
  }
33
31
  peekHead() {
34
- return this.head?.value;
32
+ if (!this.head) {
33
+ return undefined;
34
+ }
35
+ return {
36
+ value: this.head.value,
37
+ handle: this.head.handle,
38
+ };
35
39
  }
36
40
  removeByHandle(handle) {
37
- const node = this.nodes.get(handle.key);
41
+ const node = this.nodes.get(handle);
38
42
  if (!node)
39
43
  return false;
40
- this.nodes.delete(handle.key);
44
+ this.nodes.delete(handle);
41
45
  if (node.prev) {
42
46
  node.prev.next = node.next;
43
47
  }
@@ -7,5 +7,4 @@ export declare function squareRoot(n: number): number;
7
7
  * Create a function that returns: max(baseline, squareRoot(n))
8
8
  */
9
9
  export declare function squareRootWithBaseline(baseline: number): (n: number) => number;
10
- export { LinkedWaiterQueue, type EnqueueDirection, type WaiterHandle, } from "./LinkedWaiterQueue.js";
11
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AASA;;;GAGG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE5C;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAE9E;AAED,OAAO,EACL,iBAAiB,EACjB,KAAK,gBAAgB,EACrB,KAAK,YAAY,GAClB,MAAM,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AASA;;;GAGG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE5C;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,MAAM,GACf,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAEvB"}
@@ -17,4 +17,3 @@ export function squareRoot(n) {
17
17
  export function squareRootWithBaseline(baseline) {
18
18
  return (n) => Math.max(baseline, squareRoot(n));
19
19
  }
20
- export { LinkedWaiterQueue, } from "./LinkedWaiterQueue.js";
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "dynamic rate limiting"
10
10
  ],
11
11
  "author": "Ethan Resnick <ethan.resnick@gmail.com>",
12
- "version": "0.3.4",
12
+ "version": "0.4.0",
13
13
  "type": "module",
14
14
  "exports": {
15
15
  ".": {