adaptive-concurrency 0.3.2 → 0.3.4
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/LimitAllotment.d.ts +7 -1
- package/dist/LimitAllotment.d.ts.map +1 -1
- package/dist/Limiter.d.ts +15 -21
- package/dist/Limiter.d.ts.map +1 -1
- package/dist/Limiter.js +99 -56
- package/dist/RunResult.d.ts +12 -6
- package/dist/RunResult.d.ts.map +1 -1
- package/dist/RunResult.js +10 -3
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/limiter/acquire-strategies/PartitionedStrategy.d.ts +34 -5
- package/dist/limiter/acquire-strategies/PartitionedStrategy.d.ts.map +1 -1
- package/dist/limiter/acquire-strategies/PartitionedStrategy.js +34 -9
- package/dist/limiter/acquire-strategies/SemaphoreStrategy.d.ts +13 -0
- package/dist/limiter/acquire-strategies/SemaphoreStrategy.d.ts.map +1 -0
- package/dist/limiter/acquire-strategies/SemaphoreStrategy.js +23 -0
- package/dist/limiter/allocation-unavailable-strategies/BlockingBacklogRejection.d.ts +36 -0
- package/dist/limiter/allocation-unavailable-strategies/BlockingBacklogRejection.d.ts.map +1 -0
- package/dist/limiter/allocation-unavailable-strategies/BlockingBacklogRejection.js +117 -0
- package/dist/limiter/allocation-unavailable-strategies/DelayedThenBlockingRejection.d.ts +2 -1
- package/dist/limiter/allocation-unavailable-strategies/DelayedThenBlockingRejection.d.ts.map +1 -1
- package/dist/limiter/allocation-unavailable-strategies/DelayedThenBlockingRejection.js +10 -2
- package/dist/limiter/allocation-unavailable-strategies/FifoBlockingRejection.d.ts +19 -15
- package/dist/limiter/allocation-unavailable-strategies/FifoBlockingRejection.d.ts.map +1 -1
- package/dist/limiter/allocation-unavailable-strategies/FifoBlockingRejection.js +13 -61
- package/dist/limiter/allocation-unavailable-strategies/LifoBlockingRejection.d.ts +4 -8
- package/dist/limiter/allocation-unavailable-strategies/LifoBlockingRejection.d.ts.map +1 -1
- package/dist/limiter/allocation-unavailable-strategies/LifoBlockingRejection.js +13 -49
- package/dist/limiter/factories/makeBlockingLimiter.d.ts +3 -1
- package/dist/limiter/factories/makeBlockingLimiter.d.ts.map +1 -1
- package/dist/limiter/factories/makeBlockingLimiter.js +3 -2
- package/dist/limiter/factories/makeLifoBlockingLimiter.d.ts +1 -1
- package/dist/limiter/factories/makeLifoBlockingLimiter.d.ts.map +1 -1
- package/dist/limiter/factories/makeLifoBlockingLimiter.js +1 -1
- package/dist/limiter/factories/makePartitionedBlockingLimiter.d.ts +3 -1
- package/dist/limiter/factories/makePartitionedBlockingLimiter.d.ts.map +1 -1
- package/dist/limiter/factories/makePartitionedBlockingLimiter.js +5 -4
- package/dist/limiter/factories/makeSimpleLimiter.d.ts.map +1 -1
- package/dist/limiter/factories/makeSimpleLimiter.js +2 -1
- package/dist/utils/LinkedWaiterQueue.d.ts +21 -0
- package/dist/utils/LinkedWaiterQueue.d.ts.map +1 -0
- package/dist/utils/LinkedWaiterQueue.js +81 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/package.json +4 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"makeLifoBlockingLimiter.d.ts","sourceRoot":"","sources":["../../../src/limiter/factories/makeLifoBlockingLimiter.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import { Limiter
|
|
1
|
+
import { Limiter } from "../../Limiter.js";
|
|
2
2
|
import { LifoBlockingRejection, } from "../allocation-unavailable-strategies/LifoBlockingRejection.js";
|
|
3
3
|
export function makeLifoBlockingLimiter(options = {}) {
|
|
4
4
|
return new Limiter({
|
|
@@ -1,5 +1,6 @@
|
|
|
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";
|
|
3
4
|
export declare function makePartitionedBlockingLimiter<ContextT, PartitionName extends string = string>(options: {
|
|
4
5
|
partitionResolver: (context: ContextT) => PartitionName | undefined;
|
|
5
6
|
partitions: Record<PartitionName, PartitionConfig & {
|
|
@@ -7,6 +8,7 @@ export declare function makePartitionedBlockingLimiter<ContextT, PartitionName e
|
|
|
7
8
|
}>;
|
|
8
9
|
limiter?: Omit<LimiterOptions<ContextT>, "acquireStrategy">;
|
|
9
10
|
maxConcurrentDelays?: number;
|
|
10
|
-
|
|
11
|
+
backlogSize?: FifoBlockingRejectionOptions<ContextT>["backlogSize"];
|
|
12
|
+
backlogTimeout?: FifoBlockingRejectionOptions<ContextT>["backlogTimeout"];
|
|
11
13
|
}): Limiter<ContextT>;
|
|
12
14
|
//# 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,
|
|
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,8 +1,8 @@
|
|
|
1
|
-
import { Limiter
|
|
1
|
+
import { Limiter } from "../../Limiter.js";
|
|
2
|
+
import { PartitionedStrategy, } from "../acquire-strategies/PartitionedStrategy.js";
|
|
2
3
|
import { DelayedRejectStrategy } from "../allocation-unavailable-strategies/DelayedRejectStrategy.js";
|
|
3
4
|
import { DelayedThenBlockingRejection } from "../allocation-unavailable-strategies/DelayedThenBlockingRejection.js";
|
|
4
|
-
import { FifoBlockingRejection } from "../allocation-unavailable-strategies/FifoBlockingRejection.js";
|
|
5
|
-
import { PartitionedStrategy, } from "../acquire-strategies/PartitionedStrategy.js";
|
|
5
|
+
import { FifoBlockingRejection, } from "../allocation-unavailable-strategies/FifoBlockingRejection.js";
|
|
6
6
|
export function makePartitionedBlockingLimiter(options) {
|
|
7
7
|
const limit = options.limiter?.limit ?? Limiter.makeDefaultLimit();
|
|
8
8
|
const delayByPartition = new Map(Object.entries(options.partitions).map(([name, cfg]) => [
|
|
@@ -29,7 +29,8 @@ export function makePartitionedBlockingLimiter(options) {
|
|
|
29
29
|
maxConcurrentDelays: options.maxConcurrentDelays,
|
|
30
30
|
}),
|
|
31
31
|
blockingStrategy: new FifoBlockingRejection({
|
|
32
|
-
|
|
32
|
+
backlogSize: options.backlogSize,
|
|
33
|
+
backlogTimeout: options.backlogTimeout,
|
|
33
34
|
}),
|
|
34
35
|
}),
|
|
35
36
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"makeSimpleLimiter.d.ts","sourceRoot":"","sources":["../../../src/limiter/factories/makeSimpleLimiter.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"makeSimpleLimiter.d.ts","sourceRoot":"","sources":["../../../src/limiter/factories/makeSimpleLimiter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGhE,wBAAgB,iBAAiB,CAAC,QAAQ,GAAG,IAAI,EAC/C,OAAO,GAAE,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,iBAAiB,CAAM,GAC9D,OAAO,CAAC,QAAQ,CAAC,CAOnB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Limiter
|
|
1
|
+
import { Limiter } from "../../Limiter.js";
|
|
2
|
+
import { SemaphoreStrategy } from "../acquire-strategies/SemaphoreStrategy.js";
|
|
2
3
|
export function makeSimpleLimiter(options = {}) {
|
|
3
4
|
const limit = options.limit ?? Limiter.makeDefaultLimit();
|
|
4
5
|
return new Limiter({
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type WaiterHandle = {
|
|
2
|
+
key: symbol;
|
|
3
|
+
};
|
|
4
|
+
export type EnqueueDirection = "front" | "back";
|
|
5
|
+
export declare class LinkedWaiterQueue<WaiterT extends {
|
|
6
|
+
handle: WaiterHandle;
|
|
7
|
+
}> {
|
|
8
|
+
private head;
|
|
9
|
+
private tail;
|
|
10
|
+
private readonly nodes;
|
|
11
|
+
private readonly enqueueDirection;
|
|
12
|
+
private length;
|
|
13
|
+
constructor(enqueueDirection: EnqueueDirection);
|
|
14
|
+
enqueue(waiterWithoutHandle: Omit<WaiterT, "handle">, enqueueDirection?: EnqueueDirection): WaiterT;
|
|
15
|
+
peekHead(): WaiterT | undefined;
|
|
16
|
+
removeByHandle(handle: WaiterHandle): boolean;
|
|
17
|
+
size(): number;
|
|
18
|
+
private pushFront;
|
|
19
|
+
private pushBack;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=LinkedWaiterQueue.d.ts.map
|
|
@@ -0,0 +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,gBAAgB,GAAG,OAAO,GAAG,MAAM,CAAC;AAShD,qBAAa,iBAAiB,CAAC,OAAO,SAAS;IAAE,MAAM,EAAE,YAAY,CAAA;CAAE;IACrE,OAAO,CAAC,IAAI,CAAkC;IAC9C,OAAO,CAAC,IAAI,CAAkC;IAC9C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA0C;IAChE,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAmB;IACpD,OAAO,CAAC,MAAM,CAAK;gBAEP,gBAAgB,EAAE,gBAAgB;IAI9C,OAAO,CACL,mBAAmB,EAAE,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,EAC5C,gBAAgB,CAAC,EAAE,gBAAgB,GAClC,OAAO;IAwBV,QAAQ,IAAI,OAAO,GAAG,SAAS;IAI/B,cAAc,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO;IAuB7C,IAAI,IAAI,MAAM;IAId,OAAO,CAAC,SAAS;IAYjB,OAAO,CAAC,QAAQ;CAWjB"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export class LinkedWaiterQueue {
|
|
2
|
+
head;
|
|
3
|
+
tail;
|
|
4
|
+
nodes = new Map();
|
|
5
|
+
enqueueDirection;
|
|
6
|
+
length = 0;
|
|
7
|
+
constructor(enqueueDirection) {
|
|
8
|
+
this.enqueueDirection = enqueueDirection;
|
|
9
|
+
}
|
|
10
|
+
enqueue(waiterWithoutHandle, enqueueDirection) {
|
|
11
|
+
const handle = { key: Symbol("waiter-node") };
|
|
12
|
+
const waiter = {
|
|
13
|
+
...waiterWithoutHandle,
|
|
14
|
+
handle,
|
|
15
|
+
};
|
|
16
|
+
const node = {
|
|
17
|
+
handle,
|
|
18
|
+
value: waiter,
|
|
19
|
+
prev: undefined,
|
|
20
|
+
next: undefined,
|
|
21
|
+
};
|
|
22
|
+
const direction = enqueueDirection ?? this.enqueueDirection;
|
|
23
|
+
this.nodes.set(handle.key, node);
|
|
24
|
+
if (direction === "front") {
|
|
25
|
+
this.pushFront(node);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
this.pushBack(node);
|
|
29
|
+
}
|
|
30
|
+
this.length += 1;
|
|
31
|
+
return waiter;
|
|
32
|
+
}
|
|
33
|
+
peekHead() {
|
|
34
|
+
return this.head?.value;
|
|
35
|
+
}
|
|
36
|
+
removeByHandle(handle) {
|
|
37
|
+
const node = this.nodes.get(handle.key);
|
|
38
|
+
if (!node)
|
|
39
|
+
return false;
|
|
40
|
+
this.nodes.delete(handle.key);
|
|
41
|
+
if (node.prev) {
|
|
42
|
+
node.prev.next = node.next;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
this.head = node.next;
|
|
46
|
+
}
|
|
47
|
+
if (node.next) {
|
|
48
|
+
node.next.prev = node.prev;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
this.tail = node.prev;
|
|
52
|
+
}
|
|
53
|
+
node.prev = undefined;
|
|
54
|
+
node.next = undefined;
|
|
55
|
+
this.length -= 1;
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
size() {
|
|
59
|
+
return this.length;
|
|
60
|
+
}
|
|
61
|
+
pushFront(node) {
|
|
62
|
+
if (!this.head) {
|
|
63
|
+
this.head = node;
|
|
64
|
+
this.tail = node;
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
node.next = this.head;
|
|
68
|
+
this.head.prev = node;
|
|
69
|
+
this.head = node;
|
|
70
|
+
}
|
|
71
|
+
pushBack(node) {
|
|
72
|
+
if (!this.tail) {
|
|
73
|
+
this.head = node;
|
|
74
|
+
this.tail = node;
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
node.prev = this.tail;
|
|
78
|
+
this.tail.next = node;
|
|
79
|
+
this.tail = node;
|
|
80
|
+
}
|
|
81
|
+
}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -7,4 +7,5 @@ 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";
|
|
10
11
|
//# 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"}
|
|
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"}
|
package/dist/utils/index.js
CHANGED
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.
|
|
12
|
+
"version": "0.3.4",
|
|
13
13
|
"type": "module",
|
|
14
14
|
"exports": {
|
|
15
15
|
".": {
|
|
@@ -22,12 +22,13 @@
|
|
|
22
22
|
],
|
|
23
23
|
"scripts": {
|
|
24
24
|
"build": "tsc",
|
|
25
|
-
"test": "node --import tsx --test \"src/**/*.test.ts\""
|
|
25
|
+
"test": "node --import tsx --test \"src/**/*.test.ts\"",
|
|
26
|
+
"prepublishOnly": "pnpm build"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
29
|
"tsx": "^4.19.0",
|
|
29
30
|
"type-fest": "^5.5.0",
|
|
30
31
|
"type-party": "^0.7.3",
|
|
31
|
-
"typescript": "
|
|
32
|
+
"typescript": "^6.0.2"
|
|
32
33
|
}
|
|
33
34
|
}
|