adaptive-concurrency 0.3.4 → 0.5.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.
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/limiter/allocation-unavailable-strategies/BlockingBacklogRejection.d.ts +18 -12
- package/dist/limiter/allocation-unavailable-strategies/BlockingBacklogRejection.d.ts.map +1 -1
- package/dist/limiter/allocation-unavailable-strategies/BlockingBacklogRejection.js +28 -19
- package/dist/limiter/allocation-unavailable-strategies/DelayedRejectStrategy.d.ts +1 -1
- package/dist/limiter/allocation-unavailable-strategies/DelayedRejectStrategy.js +1 -1
- package/dist/limiter/factories/makeBlockingLimiter.d.ts +1 -2
- package/dist/limiter/factories/makeBlockingLimiter.d.ts.map +1 -1
- package/dist/limiter/factories/makeBlockingLimiter.js +8 -5
- package/dist/limiter/factories/makeLifoBlockingLimiter.d.ts +2 -3
- package/dist/limiter/factories/makeLifoBlockingLimiter.d.ts.map +1 -1
- package/dist/limiter/factories/makeLifoBlockingLimiter.js +7 -4
- package/dist/limiter/factories/makePartitionedBlockingLimiter.d.ts +2 -3
- package/dist/limiter/factories/makePartitionedBlockingLimiter.d.ts.map +1 -1
- package/dist/limiter/factories/makePartitionedBlockingLimiter.js +7 -4
- package/dist/limiter/factories/makePartitionedLifoBlockingLimiter.d.ts +1 -2
- package/dist/limiter/factories/makePartitionedLifoBlockingLimiter.d.ts.map +1 -1
- package/dist/limiter/factories/makePartitionedLifoBlockingLimiter.js +9 -6
- package/dist/utils/LinkedWaiterQueue.d.ts +16 -11
- package/dist/utils/LinkedWaiterQueue.d.ts.map +1 -1
- package/dist/utils/LinkedWaiterQueue.js +17 -18
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +0 -1
- 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
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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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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,42 @@
|
|
|
1
1
|
import type { LimitAllotment } from "../../LimitAllotment.js";
|
|
2
2
|
import type { AcquireResult, AllotmentUnavailableStrategy } from "../../Limiter.js";
|
|
3
|
-
import type {
|
|
4
|
-
type Waiter<ContextT> = {
|
|
3
|
+
import type { EnqueueDirection, EnqueueOptions } from "../../utils/LinkedWaiterQueue.js";
|
|
4
|
+
export type Waiter<ContextT> = {
|
|
5
5
|
context: ContextT;
|
|
6
6
|
retry: (context: ContextT) => AcquireResult;
|
|
7
|
-
handle: WaiterHandle;
|
|
8
7
|
resolve: (allotment: LimitAllotment | undefined) => void;
|
|
9
8
|
};
|
|
10
9
|
export declare const MAX_TIMEOUT: number;
|
|
11
|
-
export type BlockingBacklogRejectionOptions<ContextT> = {
|
|
10
|
+
export type BlockingBacklogRejectionOptions<ContextT, Handle> = {
|
|
12
11
|
backlogSize: number;
|
|
13
12
|
backlogTimeout: number | ((context: ContextT) => number);
|
|
14
|
-
queue: WaiterQueue<
|
|
13
|
+
queue: WaiterQueue<ContextT, Handle>;
|
|
14
|
+
enqueueDirection: EnqueueDirection | ((context: ContextT) => EnqueueDirection);
|
|
15
15
|
};
|
|
16
|
-
export type WaiterQueue<
|
|
17
|
-
enqueue: (waiter:
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
export type WaiterQueue<ContextT, Handle> = {
|
|
17
|
+
enqueue: (waiter: Waiter<ContextT>, options: EnqueueOptions) => {
|
|
18
|
+
value: Waiter<ContextT>;
|
|
19
|
+
handle: Handle;
|
|
20
|
+
};
|
|
21
|
+
peekHead: () => {
|
|
22
|
+
value: Waiter<ContextT>;
|
|
23
|
+
handle: Handle;
|
|
24
|
+
} | undefined;
|
|
25
|
+
removeByHandle: (handle: Handle) => boolean;
|
|
20
26
|
size: () => number;
|
|
21
27
|
};
|
|
22
|
-
export declare class BlockingBacklogRejection<ContextT> implements AllotmentUnavailableStrategy<ContextT> {
|
|
28
|
+
export declare class BlockingBacklogRejection<ContextT, Handle> implements AllotmentUnavailableStrategy<ContextT> {
|
|
23
29
|
private readonly backlogSize;
|
|
24
30
|
private readonly getBacklogTimeout;
|
|
31
|
+
private readonly getEnqueueOptions;
|
|
25
32
|
private readonly queue;
|
|
26
33
|
private drainInProgress;
|
|
27
34
|
private releaseDuringDrain;
|
|
28
|
-
constructor(options: BlockingBacklogRejectionOptions<ContextT>);
|
|
35
|
+
constructor(options: BlockingBacklogRejectionOptions<ContextT, Handle>);
|
|
29
36
|
onAllotmentUnavailable(context: ContextT, retry: (context: ContextT) => AcquireResult, signal?: AbortSignal): Promise<LimitAllotment | undefined>;
|
|
30
37
|
onAllotmentReleased(): Promise<void>;
|
|
31
38
|
onLimitChanged(oldLimit: number, newLimit: number): void;
|
|
32
39
|
private waitInBacklog;
|
|
33
40
|
private assertTimeoutWithinBounds;
|
|
34
41
|
}
|
|
35
|
-
export {};
|
|
36
42
|
//# 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,
|
|
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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AAwB,CACnC,QAAQ,EACR,MAAM,CACN,YAAW,4BAA4B,CAAC,QAAQ,CAAC;IACjD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAgC;IAClE,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAwC;IAC1E,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;IAoCrB,OAAO,CAAC,yBAAyB;CAUlC"}
|
|
@@ -2,28 +2,34 @@ export const MAX_TIMEOUT = 60 * 60 * 1000; // 1 hour
|
|
|
2
2
|
export class BlockingBacklogRejection {
|
|
3
3
|
backlogSize;
|
|
4
4
|
getBacklogTimeout;
|
|
5
|
+
getEnqueueOptions;
|
|
5
6
|
queue;
|
|
6
7
|
drainInProgress = false;
|
|
7
8
|
releaseDuringDrain = false;
|
|
8
9
|
constructor(options) {
|
|
9
10
|
const backlogSize = options.backlogSize;
|
|
10
|
-
if (backlogSize
|
|
11
|
-
(
|
|
12
|
-
throw new RangeError("BlockingBacklogRejection: backlogSize must be a finite number greater than or equal to 0, or Infinity");
|
|
11
|
+
if (Number.isNaN(backlogSize) || backlogSize < 0) {
|
|
12
|
+
throw new RangeError("backlogSize must be greater than or equal to 0");
|
|
13
13
|
}
|
|
14
14
|
this.backlogSize = backlogSize;
|
|
15
15
|
this.queue = options.queue;
|
|
16
16
|
const backlogTimeout = options.backlogTimeout;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
const enqueueDirection = options.enqueueDirection;
|
|
18
|
+
this.getBacklogTimeout = (() => {
|
|
19
|
+
if (typeof backlogTimeout === "number") {
|
|
20
|
+
this.assertTimeoutWithinBounds(backlogTimeout);
|
|
21
|
+
return () => backlogTimeout;
|
|
22
|
+
}
|
|
23
|
+
return (context) => {
|
|
24
|
+
const contextTimeout = backlogTimeout(context);
|
|
25
|
+
this.assertTimeoutWithinBounds(contextTimeout);
|
|
26
|
+
return contextTimeout;
|
|
27
|
+
};
|
|
28
|
+
})();
|
|
29
|
+
this.getEnqueueOptions =
|
|
30
|
+
typeof enqueueDirection === "function"
|
|
31
|
+
? (context) => ({ direction: enqueueDirection(context) })
|
|
32
|
+
: () => ({ direction: enqueueDirection });
|
|
27
33
|
}
|
|
28
34
|
onAllotmentUnavailable(context, retry, signal) {
|
|
29
35
|
if (signal?.aborted) {
|
|
@@ -45,10 +51,11 @@ export class BlockingBacklogRejection {
|
|
|
45
51
|
this.drainInProgress = true;
|
|
46
52
|
try {
|
|
47
53
|
while (this.queue.size() > 0) {
|
|
48
|
-
const
|
|
49
|
-
if (!
|
|
54
|
+
const queuedWaiter = this.queue.peekHead();
|
|
55
|
+
if (!queuedWaiter) {
|
|
50
56
|
return;
|
|
51
57
|
}
|
|
58
|
+
const waiter = queuedWaiter.value;
|
|
52
59
|
this.releaseDuringDrain = false;
|
|
53
60
|
const allotment = await waiter.retry(waiter.context);
|
|
54
61
|
if (!allotment) {
|
|
@@ -60,7 +67,7 @@ export class BlockingBacklogRejection {
|
|
|
60
67
|
}
|
|
61
68
|
return;
|
|
62
69
|
}
|
|
63
|
-
if (!this.queue.removeByHandle(
|
|
70
|
+
if (!this.queue.removeByHandle(queuedWaiter.handle)) {
|
|
64
71
|
// Waiter expired while retry was in-flight. Release the acquired slot
|
|
65
72
|
// so future retries can serve active queued waiters.
|
|
66
73
|
await allotment.releaseAndIgnore();
|
|
@@ -91,17 +98,19 @@ export class BlockingBacklogRejection {
|
|
|
91
98
|
cleanup();
|
|
92
99
|
resolve(allotment);
|
|
93
100
|
};
|
|
94
|
-
const waiter =
|
|
101
|
+
const waiter = {
|
|
95
102
|
context,
|
|
96
103
|
retry,
|
|
97
104
|
resolve: (allotment) => settle(allotment),
|
|
98
|
-
}
|
|
105
|
+
};
|
|
106
|
+
const enqueueOptions = this.getEnqueueOptions(context);
|
|
107
|
+
const { handle } = this.queue.enqueue(waiter, enqueueOptions);
|
|
99
108
|
const timer = setTimeout(() => settle(undefined), timeout);
|
|
100
109
|
const onAbort = () => settle(undefined);
|
|
101
110
|
const cleanup = () => {
|
|
102
111
|
clearTimeout(timer);
|
|
103
112
|
signal?.removeEventListener("abort", onAbort);
|
|
104
|
-
this.queue.removeByHandle(
|
|
113
|
+
this.queue.removeByHandle(handle);
|
|
105
114
|
};
|
|
106
115
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
107
116
|
});
|
|
@@ -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
|
|
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
|
|
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?:
|
|
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,
|
|
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,CAUnB"}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { Limiter
|
|
2
|
-
import {
|
|
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
|
|
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
|
+
enqueueDirection: "back",
|
|
11
|
+
queue: new LinkedWaiterQueue(),
|
|
9
12
|
}),
|
|
10
13
|
});
|
|
11
14
|
}
|
|
@@ -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?:
|
|
5
|
-
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;
|
|
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,CAUnB"}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { Limiter } from "../../Limiter.js";
|
|
2
|
-
import {
|
|
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
|
|
7
|
-
backlogSize: options.backlogSize,
|
|
8
|
-
backlogTimeout: options.backlogTimeout,
|
|
7
|
+
allotmentUnavailableStrategy: new BlockingBacklogRejection({
|
|
8
|
+
backlogSize: options.backlogSize ?? 100,
|
|
9
|
+
backlogTimeout: options.backlogTimeout ?? 1_000,
|
|
10
|
+
enqueueDirection: "front",
|
|
11
|
+
queue: new LinkedWaiterQueue(),
|
|
9
12
|
}),
|
|
10
13
|
});
|
|
11
14
|
}
|
|
@@ -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?:
|
|
12
|
-
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;
|
|
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,CAmCpB"}
|
|
@@ -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,11 @@ export function makePartitionedBlockingLimiter(options) {
|
|
|
28
29
|
},
|
|
29
30
|
maxConcurrentDelays: options.maxConcurrentDelays,
|
|
30
31
|
}),
|
|
31
|
-
blockingStrategy: new
|
|
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
|
+
enqueueDirection: "back",
|
|
36
|
+
queue: new LinkedWaiterQueue(),
|
|
34
37
|
}),
|
|
35
38
|
}),
|
|
36
39
|
});
|
|
@@ -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?:
|
|
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,
|
|
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,CAoCpB"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Limiter
|
|
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,11 @@ export function makePartitionedLifoBlockingLimiter(options) {
|
|
|
28
29
|
},
|
|
29
30
|
maxConcurrentDelays: options.maxConcurrentDelays,
|
|
30
31
|
}),
|
|
31
|
-
blockingStrategy: new
|
|
32
|
-
backlogSize: options.backlogSize,
|
|
33
|
-
backlogTimeout: options.backlogTimeout,
|
|
32
|
+
blockingStrategy: new BlockingBacklogRejection({
|
|
33
|
+
backlogSize: options.backlogSize ?? 100,
|
|
34
|
+
backlogTimeout: options.backlogTimeout ?? 1_000,
|
|
35
|
+
enqueueDirection: "front",
|
|
36
|
+
queue: new LinkedWaiterQueue(),
|
|
34
37
|
}),
|
|
35
38
|
}),
|
|
36
39
|
});
|
|
@@ -1,21 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
};
|
|
1
|
+
declare class ItemHandle {
|
|
2
|
+
}
|
|
4
3
|
export type EnqueueDirection = "front" | "back";
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
}
|
|
4
|
+
export type EnqueueOptions = {
|
|
5
|
+
direction: EnqueueDirection;
|
|
6
|
+
};
|
|
7
|
+
export declare class LinkedWaiterQueue<T extends object> {
|
|
8
8
|
private head;
|
|
9
9
|
private tail;
|
|
10
10
|
private readonly nodes;
|
|
11
|
-
private readonly enqueueDirection;
|
|
12
11
|
private length;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
enqueue(value: T, options: EnqueueOptions): {
|
|
13
|
+
value: T;
|
|
14
|
+
handle: ItemHandle;
|
|
15
|
+
};
|
|
16
|
+
peekHead(): {
|
|
17
|
+
value: T;
|
|
18
|
+
handle: ItemHandle;
|
|
19
|
+
} | undefined;
|
|
20
|
+
removeByHandle(handle: ItemHandle): boolean;
|
|
17
21
|
size(): number;
|
|
18
22
|
private pushFront;
|
|
19
23
|
private pushBack;
|
|
20
24
|
}
|
|
25
|
+
export {};
|
|
21
26
|
//# 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,
|
|
1
|
+
{"version":3,"file":"LinkedWaiterQueue.d.ts","sourceRoot":"","sources":["../../src/utils/LinkedWaiterQueue.ts"],"names":[],"mappings":"AAAA,cAAM,UAAU;CAAG;AAEnB,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,MAAM,CAAC;AAChD,MAAM,MAAM,cAAc,GAAG;IAC3B,SAAS,EAAE,gBAAgB,CAAC;CAC7B,CAAC;AASF,qBAAa,iBAAiB,CAAC,CAAC,SAAS,MAAM;IAC7C,OAAO,CAAC,IAAI,CAA4B;IACxC,OAAO,CAAC,IAAI,CAA4B;IACxC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAwC;IAC9D,OAAO,CAAC,MAAM,CAAK;IAEnB,OAAO,CACL,KAAK,EAAE,CAAC,EACR,OAAO,EAAE,cAAc,GACtB;QAAE,KAAK,EAAE,CAAC,CAAC;QAAC,MAAM,EAAE,UAAU,CAAA;KAAE;IAoBnC,QAAQ,IAAI;QAAE,KAAK,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,43 +1,42 @@
|
|
|
1
|
+
class ItemHandle {
|
|
2
|
+
}
|
|
1
3
|
export class LinkedWaiterQueue {
|
|
2
4
|
head;
|
|
3
5
|
tail;
|
|
4
6
|
nodes = new Map();
|
|
5
|
-
enqueueDirection;
|
|
6
7
|
length = 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
enqueue(waiterWithoutHandle, enqueueDirection) {
|
|
11
|
-
const handle = { key: Symbol("waiter-node") };
|
|
12
|
-
const waiter = {
|
|
13
|
-
...waiterWithoutHandle,
|
|
14
|
-
handle,
|
|
15
|
-
};
|
|
8
|
+
enqueue(value, options) {
|
|
9
|
+
const handle = new ItemHandle();
|
|
16
10
|
const node = {
|
|
17
11
|
handle,
|
|
18
|
-
value:
|
|
12
|
+
value: value,
|
|
19
13
|
prev: undefined,
|
|
20
14
|
next: undefined,
|
|
21
15
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (direction === "front") {
|
|
16
|
+
this.nodes.set(handle, node);
|
|
17
|
+
if (options.direction === "front") {
|
|
25
18
|
this.pushFront(node);
|
|
26
19
|
}
|
|
27
20
|
else {
|
|
28
21
|
this.pushBack(node);
|
|
29
22
|
}
|
|
30
23
|
this.length += 1;
|
|
31
|
-
return
|
|
24
|
+
return { value, handle };
|
|
32
25
|
}
|
|
33
26
|
peekHead() {
|
|
34
|
-
|
|
27
|
+
if (!this.head) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
value: this.head.value,
|
|
32
|
+
handle: this.head.handle,
|
|
33
|
+
};
|
|
35
34
|
}
|
|
36
35
|
removeByHandle(handle) {
|
|
37
|
-
const node = this.nodes.get(handle
|
|
36
|
+
const node = this.nodes.get(handle);
|
|
38
37
|
if (!node)
|
|
39
38
|
return false;
|
|
40
|
-
this.nodes.delete(handle
|
|
39
|
+
this.nodes.delete(handle);
|
|
41
40
|
if (node.prev) {
|
|
42
41
|
node.prev.next = node.next;
|
|
43
42
|
}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -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,
|
|
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"}
|
package/dist/utils/index.js
CHANGED