async-queue-runner 0.17.0 → 0.19.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/_cjs/queue.js +4 -3
- package/_cjs/utils.js +8 -1
- package/_esm/queue.js +4 -3
- package/_esm/utils.js +6 -0
- package/_types/utils.d.ts +5 -1
- package/package.json +1 -1
package/_cjs/queue.js
CHANGED
|
@@ -49,14 +49,18 @@ class AsyncQueue {
|
|
|
49
49
|
}
|
|
50
50
|
const item = this.queue.shift();
|
|
51
51
|
const action = this.processQueueItem(item);
|
|
52
|
+
const actionName = action.constructor.name || 'some undefined';
|
|
53
|
+
this.logger.setContext(actionName);
|
|
52
54
|
const isLocking = action.locking;
|
|
53
55
|
const scope = action.scope;
|
|
54
56
|
if (isLocking) {
|
|
55
57
|
if (this.locker.isLocked(scope)) {
|
|
58
|
+
this.logger.info(`Queue(${this.name}): waiting for scope to unlock`);
|
|
56
59
|
await this.locker.wait(scope);
|
|
57
60
|
}
|
|
58
61
|
this.locker.lock(scope);
|
|
59
62
|
}
|
|
63
|
+
this.logger.info(`Queue(${this.name}): running action`);
|
|
60
64
|
await this.iterate(action);
|
|
61
65
|
if (isLocking) {
|
|
62
66
|
this.locker.unlock(scope);
|
|
@@ -70,9 +74,6 @@ class AsyncQueue {
|
|
|
70
74
|
}
|
|
71
75
|
}
|
|
72
76
|
async iterate(action) {
|
|
73
|
-
const actionName = action.constructor.name || 'some undefined';
|
|
74
|
-
this.logger.setContext(actionName);
|
|
75
|
-
this.logger.info(`Queue(${this.name}): running action`);
|
|
76
77
|
await action.execute(this.context);
|
|
77
78
|
await this.delay(action.delay);
|
|
78
79
|
}
|
package/_cjs/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.util = exports.Delay = void 0;
|
|
3
|
+
exports.util = exports.Abort = exports.Delay = void 0;
|
|
4
4
|
const action_js_1 = require("./action.js");
|
|
5
5
|
class Delay extends action_js_1.Action {
|
|
6
6
|
async execute() {
|
|
@@ -10,6 +10,12 @@ class Delay extends action_js_1.Action {
|
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
exports.Delay = Delay;
|
|
13
|
+
class Abort extends action_js_1.Action {
|
|
14
|
+
async execute(context) {
|
|
15
|
+
context.abort();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.Abort = Abort;
|
|
13
19
|
exports.util = {
|
|
14
20
|
delay(timeout) {
|
|
15
21
|
return new Delay({ delay: timeout });
|
|
@@ -39,4 +45,5 @@ exports.util = {
|
|
|
39
45
|
}
|
|
40
46
|
return new Validator();
|
|
41
47
|
},
|
|
48
|
+
abort: new Abort(),
|
|
42
49
|
};
|
package/_esm/queue.js
CHANGED
|
@@ -46,14 +46,18 @@ export class AsyncQueue {
|
|
|
46
46
|
}
|
|
47
47
|
const item = this.queue.shift();
|
|
48
48
|
const action = this.processQueueItem(item);
|
|
49
|
+
const actionName = action.constructor.name || 'some undefined';
|
|
50
|
+
this.logger.setContext(actionName);
|
|
49
51
|
const isLocking = action.locking;
|
|
50
52
|
const scope = action.scope;
|
|
51
53
|
if (isLocking) {
|
|
52
54
|
if (this.locker.isLocked(scope)) {
|
|
55
|
+
this.logger.info(`Queue(${this.name}): waiting for scope to unlock`);
|
|
53
56
|
await this.locker.wait(scope);
|
|
54
57
|
}
|
|
55
58
|
this.locker.lock(scope);
|
|
56
59
|
}
|
|
60
|
+
this.logger.info(`Queue(${this.name}): running action`);
|
|
57
61
|
await this.iterate(action);
|
|
58
62
|
if (isLocking) {
|
|
59
63
|
this.locker.unlock(scope);
|
|
@@ -67,9 +71,6 @@ export class AsyncQueue {
|
|
|
67
71
|
}
|
|
68
72
|
}
|
|
69
73
|
async iterate(action) {
|
|
70
|
-
const actionName = action.constructor.name || 'some undefined';
|
|
71
|
-
this.logger.setContext(actionName);
|
|
72
|
-
this.logger.info(`Queue(${this.name}): running action`);
|
|
73
74
|
await action.execute(this.context);
|
|
74
75
|
await this.delay(action.delay);
|
|
75
76
|
}
|
package/_esm/utils.js
CHANGED
|
@@ -6,6 +6,11 @@ export class Delay extends Action {
|
|
|
6
6
|
});
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
+
export class Abort extends Action {
|
|
10
|
+
async execute(context) {
|
|
11
|
+
context.abort();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
9
14
|
export const util = {
|
|
10
15
|
delay(timeout) {
|
|
11
16
|
return new Delay({ delay: timeout });
|
|
@@ -35,4 +40,5 @@ export const util = {
|
|
|
35
40
|
}
|
|
36
41
|
return new Validator();
|
|
37
42
|
},
|
|
43
|
+
abort: new Abort(),
|
|
38
44
|
};
|
package/_types/utils.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { Action } from "./action.js";
|
|
2
|
-
import { Branches, IAction } from "./types.js";
|
|
2
|
+
import { Branches, QueueContext, IAction } from "./types.js";
|
|
3
3
|
export declare class Delay extends Action<null> {
|
|
4
4
|
execute(): Promise<void>;
|
|
5
5
|
}
|
|
6
|
+
export declare class Abort extends Action<null> {
|
|
7
|
+
execute(context: QueueContext): Promise<void>;
|
|
8
|
+
}
|
|
6
9
|
export declare const util: {
|
|
7
10
|
delay(timeout: number): Delay;
|
|
8
11
|
if<C>(condition: (context: C) => Promise<boolean> | boolean, branches: Branches): IAction;
|
|
9
12
|
valid<C_1>(validator: (context: C_1) => Promise<boolean> | boolean, actions: IAction[]): IAction;
|
|
13
|
+
abort: Abort;
|
|
10
14
|
};
|