@plugola/queue 1.0.1 → 1.2.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/Asyncable.d.ts +2 -0
- package/dist/Asyncable.js +36 -0
- package/dist/Asyncable.js.map +1 -0
- package/dist/MethodQueue.d.ts +1 -1
- package/dist/MethodQueue.js.map +1 -1
- package/dist/Queue.d.ts +4 -3
- package/dist/Queue.js +9 -8
- package/dist/Queue.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
2
|
+
export function Asyncable(Class, onError) {
|
|
3
|
+
var _AsyncQueue_instances, _AsyncQueue_promise, _AsyncQueue_resumed, _AsyncQueue_whenRunning;
|
|
4
|
+
class AsyncQueue extends Class {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
_AsyncQueue_instances.add(this);
|
|
8
|
+
_AsyncQueue_promise.set(this, Promise.resolve());
|
|
9
|
+
_AsyncQueue_resumed.set(this, Promise.withResolvers());
|
|
10
|
+
}
|
|
11
|
+
pause() {
|
|
12
|
+
if (this.running)
|
|
13
|
+
__classPrivateFieldSet(this, _AsyncQueue_resumed, Promise.withResolvers(), "f");
|
|
14
|
+
super.pause();
|
|
15
|
+
}
|
|
16
|
+
resume() {
|
|
17
|
+
__classPrivateFieldGet(this, _AsyncQueue_resumed, "f").resolve();
|
|
18
|
+
super.resume();
|
|
19
|
+
}
|
|
20
|
+
execItems(exec, items) {
|
|
21
|
+
while (this.running && items.length > 0) {
|
|
22
|
+
const item = items.shift();
|
|
23
|
+
const next = __classPrivateFieldGet(this, _AsyncQueue_promise, "f")
|
|
24
|
+
.then(() => __classPrivateFieldGet(this, _AsyncQueue_instances, "m", _AsyncQueue_whenRunning).call(this))
|
|
25
|
+
.then(() => exec(item));
|
|
26
|
+
__classPrivateFieldSet(this, _AsyncQueue_promise, onError ? next.catch(onError) : next, "f");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
_AsyncQueue_promise = new WeakMap(), _AsyncQueue_resumed = new WeakMap(), _AsyncQueue_instances = new WeakSet(), _AsyncQueue_whenRunning = async function _AsyncQueue_whenRunning() {
|
|
31
|
+
while (!this.running)
|
|
32
|
+
await __classPrivateFieldGet(this, _AsyncQueue_resumed, "f").promise;
|
|
33
|
+
};
|
|
34
|
+
return AsyncQueue;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=Asyncable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Asyncable.js","sourceRoot":"","sources":["../src/Asyncable.ts"],"names":[],"mappings":";AAEA,MAAM,UAAU,SAAS,CACvB,KAAQ,EACR,OAAkC;;IAElC,MAAM,UAAW,SAAQ,KAAK;QAA9B;;;YACE,8BAA6B,OAAO,CAAC,OAAO,EAAE,EAAA;YAC9C,8BAAW,OAAO,CAAC,aAAa,EAAQ,EAAA;QAyB1C,CAAC;QAvBU,KAAK;YACZ,IAAI,IAAI,CAAC,OAAO;gBAAE,uBAAA,IAAI,uBAAY,OAAO,CAAC,aAAa,EAAE,MAAA,CAAA;YACzD,KAAK,CAAC,KAAK,EAAE,CAAA;QACf,CAAC;QAEQ,MAAM;YACb,uBAAA,IAAI,2BAAS,CAAC,OAAO,EAAE,CAAA;YACvB,KAAK,CAAC,MAAM,EAAE,CAAA;QAChB,CAAC;QAEkB,SAAS,CAAC,IAAwB,EAAE,KAAY;YACjE,OAAO,IAAI,CAAC,OAAO,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACxC,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,EAAE,CAAA;gBAC1B,MAAM,IAAI,GAAG,uBAAA,IAAI,2BAAS;qBACvB,IAAI,CAAC,GAAG,EAAE,CAAC,uBAAA,IAAI,sDAAa,MAAjB,IAAI,CAAe,CAAC;qBAC/B,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;gBACzB,uBAAA,IAAI,uBAAY,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,MAAA,CAAA;YACtD,CAAC;QACH,CAAC;KAKF;+IAHC,KAAK;QACH,OAAO,CAAC,IAAI,CAAC,OAAO;YAAE,MAAM,uBAAA,IAAI,2BAAS,CAAC,OAAO,CAAA;IACnD,CAAC;IAGH,OAAO,UAAU,CAAA;AACnB,CAAC"}
|
package/dist/MethodQueue.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Queue } from './Queue.ts';
|
|
2
|
-
export declare class MethodQueue extends Queue<() => any> {
|
|
2
|
+
export declare class MethodQueue extends Queue<() => any, any> {
|
|
3
3
|
constructor();
|
|
4
4
|
queueMethod<R, Args extends unknown[]>(method: (...args: Args) => R): (...args: Args) => Promise<Awaited<R>>;
|
|
5
5
|
push<R>(fn: () => R): Promise<Awaited<R>>;
|
package/dist/MethodQueue.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MethodQueue.js","sourceRoot":"","sources":["../src/MethodQueue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAElC,MAAM,OAAO,WAAY,SAAQ,
|
|
1
|
+
{"version":3,"file":"MethodQueue.js","sourceRoot":"","sources":["../src/MethodQueue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAElC,MAAM,OAAO,WAAY,SAAQ,KAAqB;IACpD;QACE,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAA;IACrB,CAAC;IAED,WAAW,CACT,MAA4B;QAE5B,OAAO,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA;IACtD,CAAC;IAEQ,IAAI,CAAI,EAAW;QAC1B,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,aAAa,EAAc,CAAA;QACxE,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE;YACd,IAAI,CAAC;gBACH,OAAO,CAAC,EAAE,EAAgB,CAAC,CAAA;YAC7B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,CAAC,KAAK,CAAC,CAAA;YACf,CAAC;QACH,CAAC,CAAC,CAAA;QACF,OAAO,OAAO,CAAA;IAChB,CAAC;CACF"}
|
package/dist/Queue.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { Runnable } from './Runnable.ts';
|
|
2
|
-
export declare class Queue<T> implements Runnable {
|
|
2
|
+
export declare class Queue<T, R = void> implements Runnable {
|
|
3
3
|
#private;
|
|
4
4
|
protected readonly items: T[];
|
|
5
|
-
constructor(exec: (item: T) =>
|
|
5
|
+
constructor(exec: (item: T) => R, items?: T[]);
|
|
6
6
|
get running(): boolean;
|
|
7
|
-
push(
|
|
7
|
+
push(...items: T[]): void;
|
|
8
8
|
resume(): void;
|
|
9
9
|
pause(): void;
|
|
10
|
+
protected execItems(exec: (item: T) => R, items: T[]): void;
|
|
10
11
|
}
|
package/dist/Queue.js
CHANGED
|
@@ -10,23 +10,24 @@ export class Queue {
|
|
|
10
10
|
get running() {
|
|
11
11
|
return __classPrivateFieldGet(this, _Queue_running, "f");
|
|
12
12
|
}
|
|
13
|
-
push(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
this.items.push(item);
|
|
13
|
+
push(...items) {
|
|
14
|
+
this.execItems(__classPrivateFieldGet(this, _Queue_exec, "f"), items);
|
|
15
|
+
if (items.length)
|
|
16
|
+
this.items.push(...items);
|
|
18
17
|
}
|
|
19
18
|
resume() {
|
|
20
19
|
if (__classPrivateFieldGet(this, _Queue_running, "f"))
|
|
21
20
|
return;
|
|
22
21
|
__classPrivateFieldSet(this, _Queue_running, true, "f");
|
|
23
|
-
|
|
24
|
-
while (__classPrivateFieldGet(this, _Queue_running, "f") && (item = this.items.shift()))
|
|
25
|
-
this.push(item);
|
|
22
|
+
this.execItems(__classPrivateFieldGet(this, _Queue_exec, "f"), this.items);
|
|
26
23
|
}
|
|
27
24
|
pause() {
|
|
28
25
|
__classPrivateFieldSet(this, _Queue_running, false, "f");
|
|
29
26
|
}
|
|
27
|
+
execItems(exec, items) {
|
|
28
|
+
while (__classPrivateFieldGet(this, _Queue_running, "f") && items.length > 0)
|
|
29
|
+
exec(items.shift());
|
|
30
|
+
}
|
|
30
31
|
}
|
|
31
32
|
_Queue_exec = new WeakMap(), _Queue_running = new WeakMap();
|
|
32
33
|
//# sourceMappingURL=Queue.js.map
|
package/dist/Queue.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Queue.js","sourceRoot":"","sources":["../src/Queue.ts"],"names":[],"mappings":";;AAEA,MAAM,OAAO,KAAK;IAIhB,YAAY,
|
|
1
|
+
{"version":3,"file":"Queue.js","sourceRoot":"","sources":["../src/Queue.ts"],"names":[],"mappings":";;AAEA,MAAM,OAAO,KAAK;IAIhB,YAAY,IAAoB,EAAE,KAAK,GAAQ,EAAE;QAHjD,8BAAqB;QAQrB,yBAAW,KAAK,EAAA;QAJd,uBAAA,IAAI,eAAS,IAAI,MAAA,CAAA;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;IAGD,IAAI,OAAO;QACT,OAAO,uBAAA,IAAI,sBAAS,CAAA;IACtB,CAAC;IAED,IAAI,CAAC,GAAG,KAAU;QAChB,IAAI,CAAC,SAAS,CAAC,uBAAA,IAAI,mBAAM,EAAE,KAAK,CAAC,CAAA;QACjC,IAAI,KAAK,CAAC,MAAM;YAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAA;IAC7C,CAAC;IAED,MAAM;QACJ,IAAI,uBAAA,IAAI,sBAAS;YAAE,OAAM;QACzB,uBAAA,IAAI,kBAAY,IAAI,MAAA,CAAA;QACpB,IAAI,CAAC,SAAS,CAAC,uBAAA,IAAI,mBAAM,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;IACxC,CAAC;IAED,KAAK;QACH,uBAAA,IAAI,kBAAY,KAAK,MAAA,CAAA;IACvB,CAAC;IAES,SAAS,CAAC,IAAoB,EAAE,KAAU;QAClD,OAAO,uBAAA,IAAI,sBAAS,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;YAAE,IAAI,CAAC,KAAK,CAAC,KAAK,EAAG,CAAC,CAAA;IAChE,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plugola/queue",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Runnable queues that buffer while stopped and drain on start",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/node": "26.6.6",
|
|
28
28
|
"@vitest/runner": "4.1.11",
|
|
29
|
-
"rimraf": "6.1.
|
|
29
|
+
"rimraf": "6.1.4",
|
|
30
30
|
"ts-node": "10.9.2",
|
|
31
31
|
"typescript": "7.0.2",
|
|
32
32
|
"vitest": "5.1.0"
|