adaptive-concurrency 0.6.1 → 0.7.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.
|
@@ -10,6 +10,9 @@ export declare class LinkedWaiterQueue<T extends object> {
|
|
|
10
10
|
private readonly nodes;
|
|
11
11
|
private maxPriority;
|
|
12
12
|
private length;
|
|
13
|
+
private shuttingDown;
|
|
14
|
+
private shutdownPromise;
|
|
15
|
+
private resolveShutdown;
|
|
13
16
|
enqueue(value: T, options: EnqueueOptions): {
|
|
14
17
|
value: T;
|
|
15
18
|
handle: ItemHandle;
|
|
@@ -19,10 +22,12 @@ export declare class LinkedWaiterQueue<T extends object> {
|
|
|
19
22
|
handle: ItemHandle;
|
|
20
23
|
} | undefined;
|
|
21
24
|
removeByHandle(handle: ItemHandle): boolean;
|
|
25
|
+
shutdown(): Promise<void>;
|
|
22
26
|
size(): number;
|
|
23
27
|
private getOrCreateBucket;
|
|
24
28
|
private insertInBucket;
|
|
25
29
|
private unlinkFromBucket;
|
|
30
|
+
private maybeResolveShutdown;
|
|
26
31
|
}
|
|
27
32
|
export {};
|
|
28
33
|
//# sourceMappingURL=LinkedWaiterQueue.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
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;IAC5B,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC/B,CAAC;AAkBF,qBAAa,iBAAiB,CAAC,CAAC,SAAS,MAAM;IAC7C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAwC;IAChE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAwC;IAC9D,OAAO,CAAC,WAAW,CAAqB;IACxC,OAAO,CAAC,MAAM,CAAK;
|
|
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;IAC5B,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC/B,CAAC;AAkBF,qBAAa,iBAAiB,CAAC,CAAC,SAAS,MAAM;IAC7C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAwC;IAChE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAwC;IAC9D,OAAO,CAAC,WAAW,CAAqB;IACxC,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,eAAe,CAA4B;IACnD,OAAO,CAAC,eAAe,CAA2B;IAElD,OAAO,CACL,KAAK,EAAE,CAAC,EACR,OAAO,EAAE,cAAc,GACtB;QAAE,KAAK,EAAE,CAAC,CAAC;QAAC,MAAM,EAAE,UAAU,CAAA;KAAE;IA8BnC,QAAQ,IAAI;QAAE,KAAK,EAAE,CAAC,CAAC;QAAC,MAAM,EAAE,UAAU,CAAA;KAAE,GAAG,SAAS;IAcxD,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO;IAc3C,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAYzB,IAAI,IAAI,MAAM;IAId,OAAO,CAAC,iBAAiB;IAezB,OAAO,CAAC,cAAc;IAwBtB,OAAO,CAAC,gBAAgB;IAgCxB,OAAO,CAAC,oBAAoB;CAQ7B"}
|
|
@@ -5,7 +5,13 @@ export class LinkedWaiterQueue {
|
|
|
5
5
|
nodes = new Map();
|
|
6
6
|
maxPriority;
|
|
7
7
|
length = 0;
|
|
8
|
+
shuttingDown = false;
|
|
9
|
+
shutdownPromise;
|
|
10
|
+
resolveShutdown;
|
|
8
11
|
enqueue(value, options) {
|
|
12
|
+
if (this.shuttingDown) {
|
|
13
|
+
throw new Error("queue has been shut down");
|
|
14
|
+
}
|
|
9
15
|
const handle = new ItemHandle();
|
|
10
16
|
const priority = options.priority ?? 0;
|
|
11
17
|
if (!Number.isFinite(priority)) {
|
|
@@ -50,8 +56,19 @@ export class LinkedWaiterQueue {
|
|
|
50
56
|
node.prev = undefined;
|
|
51
57
|
node.next = undefined;
|
|
52
58
|
this.length -= 1;
|
|
59
|
+
this.maybeResolveShutdown();
|
|
53
60
|
return true;
|
|
54
61
|
}
|
|
62
|
+
shutdown() {
|
|
63
|
+
if (!this.shuttingDown) {
|
|
64
|
+
this.shuttingDown = true;
|
|
65
|
+
this.shutdownPromise = new Promise((resolve) => {
|
|
66
|
+
this.resolveShutdown = resolve;
|
|
67
|
+
});
|
|
68
|
+
this.maybeResolveShutdown();
|
|
69
|
+
}
|
|
70
|
+
return this.shutdownPromise;
|
|
71
|
+
}
|
|
55
72
|
size() {
|
|
56
73
|
return this.length;
|
|
57
74
|
}
|
|
@@ -125,4 +142,11 @@ export class LinkedWaiterQueue {
|
|
|
125
142
|
}
|
|
126
143
|
this.maxPriority = newMax;
|
|
127
144
|
}
|
|
145
|
+
maybeResolveShutdown() {
|
|
146
|
+
if (!this.shuttingDown || this.length !== 0 || !this.resolveShutdown) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
this.resolveShutdown();
|
|
150
|
+
this.resolveShutdown = undefined;
|
|
151
|
+
}
|
|
128
152
|
}
|