async-queue-runner 0.10.0 → 0.12.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/package.json CHANGED
@@ -1,4 +1,4 @@
1
- {
2
- "type": "commonjs"
3
- }
4
-
1
+ {
2
+ "type": "commonjs"
3
+ }
4
+
package/_cjs/queue.js CHANGED
@@ -12,11 +12,16 @@ class AsyncQueue {
12
12
  stop: () => { this.loopAction = false; },
13
13
  extend: (obj) => Object.assign(this.context, obj),
14
14
  name: () => this.name,
15
+ abort: () => {
16
+ while (this.queue.length > 0) {
17
+ this.queue.pop();
18
+ }
19
+ },
15
20
  };
16
21
  constructor(opts) {
17
22
  this.queue = opts.actions;
18
23
  this.name = opts.name;
19
- this.end = opts.end;
24
+ this.end = opts.end || (() => { });
20
25
  }
21
26
  async delay(timeout) {
22
27
  return new Promise((res) => setTimeout(res, timeout));
package/_esm/action.js CHANGED
@@ -1,7 +1,11 @@
1
- export class Action {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Action = void 0;
4
+ class Action {
2
5
  delay = 0;
3
6
  constructor(opts = {}) {
4
7
  if (opts.delay)
5
8
  this.delay = opts.delay;
6
9
  }
7
10
  }
11
+ exports.Action = Action;
package/_esm/index.js CHANGED
@@ -1,4 +1,11 @@
1
- export { QueueRunner } from './runner.js';
2
- export { AsyncQueue } from './queue.js';
3
- export { Action } from './action.js';
4
- export { util } from './utils.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.util = exports.Action = exports.AsyncQueue = exports.QueueRunner = void 0;
4
+ var runner_js_1 = require("./runner.js");
5
+ Object.defineProperty(exports, "QueueRunner", { enumerable: true, get: function () { return runner_js_1.QueueRunner; } });
6
+ var queue_js_1 = require("./queue.js");
7
+ Object.defineProperty(exports, "AsyncQueue", { enumerable: true, get: function () { return queue_js_1.AsyncQueue; } });
8
+ var action_js_1 = require("./action.js");
9
+ Object.defineProperty(exports, "Action", { enumerable: true, get: function () { return action_js_1.Action; } });
10
+ var utils_js_1 = require("./utils.js");
11
+ Object.defineProperty(exports, "util", { enumerable: true, get: function () { return utils_js_1.util; } });
package/_esm/package.json CHANGED
@@ -1,4 +1,4 @@
1
- {
2
- "type": "module"
3
- }
4
-
1
+ {
2
+ "type": "module"
3
+ }
4
+
package/_esm/queue.js CHANGED
@@ -1,5 +1,8 @@
1
- import { Action } from './action.js';
2
- export class AsyncQueue {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AsyncQueue = void 0;
4
+ const action_js_1 = require("./action.js");
5
+ class AsyncQueue {
3
6
  name = 'default queue name';
4
7
  queue = [];
5
8
  end;
@@ -9,11 +12,16 @@ export class AsyncQueue {
9
12
  stop: () => { this.loopAction = false; },
10
13
  extend: (obj) => Object.assign(this.context, obj),
11
14
  name: () => this.name,
15
+ abort: () => {
16
+ while (this.queue.length > 0) {
17
+ this.queue.pop();
18
+ }
19
+ },
12
20
  };
13
21
  constructor(opts) {
14
22
  this.queue = opts.actions;
15
23
  this.name = opts.name;
16
- this.end = opts.end;
24
+ this.end = opts.end || (() => { });
17
25
  }
18
26
  async delay(timeout) {
19
27
  return new Promise((res) => setTimeout(res, timeout));
@@ -49,10 +57,11 @@ export class AsyncQueue {
49
57
  this.queue.unshift(...actions);
50
58
  }
51
59
  processQueueItem(item) {
52
- if (item instanceof Action) {
60
+ if (item instanceof action_js_1.Action) {
53
61
  return item;
54
62
  }
55
63
  else
56
64
  return new item;
57
65
  }
58
66
  }
67
+ exports.AsyncQueue = AsyncQueue;
package/_esm/runner.js CHANGED
@@ -1,9 +1,12 @@
1
- import { AsyncQueue } from "./queue.js";
2
- export class QueueRunner {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QueueRunner = void 0;
4
+ const queue_js_1 = require("./queue.js");
5
+ class QueueRunner {
3
6
  queues = new Map();
4
7
  listeners = [];
5
8
  add(actions, context = {}, name = this.getName()) {
6
- const queue = new AsyncQueue({
9
+ const queue = new queue_js_1.AsyncQueue({
7
10
  name, actions,
8
11
  end: () => {
9
12
  this.queues.delete(name);
@@ -25,3 +28,4 @@ export class QueueRunner {
25
28
  return Math.random().toString(36).substring(2, 10);
26
29
  }
27
30
  }
31
+ exports.QueueRunner = QueueRunner;
package/_esm/types.js CHANGED
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/_esm/utils.js CHANGED
@@ -1,17 +1,21 @@
1
- import { Action } from "./action.js";
2
- export class Delay extends Action {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.util = exports.Delay = void 0;
4
+ const action_js_1 = require("./action.js");
5
+ class Delay extends action_js_1.Action {
3
6
  async execute() {
4
7
  return new Promise(res => {
5
8
  setTimeout(res, this.delay);
6
9
  });
7
10
  }
8
11
  }
9
- export const util = {
12
+ exports.Delay = Delay;
13
+ exports.util = {
10
14
  delay(timeout) {
11
15
  return new Delay({ delay: timeout });
12
16
  },
13
17
  if(condition, branches) {
14
- class IfAction extends Action {
18
+ class IfAction extends action_js_1.Action {
15
19
  async execute(context) {
16
20
  const result = await condition(context);
17
21
  if (result) {
@@ -25,7 +29,7 @@ export const util = {
25
29
  return new IfAction();
26
30
  },
27
31
  valid(validator, actions) {
28
- class Validator extends Action {
32
+ class Validator extends action_js_1.Action {
29
33
  async execute(context) {
30
34
  const valid = await validator(context);
31
35
  if (valid) {
package/_types/queue.d.ts CHANGED
@@ -2,7 +2,7 @@ import { IAction, QueueAction, QueueContext } from './types.js';
2
2
  export type QueueOpts = {
3
3
  actions: QueueAction[];
4
4
  name: string;
5
- end: () => void;
5
+ end?: () => void;
6
6
  };
7
7
  export declare class AsyncQueue {
8
8
  name: string;
package/_types/types.d.ts CHANGED
@@ -13,4 +13,5 @@ export type QueueContext = {
13
13
  extend: (obj: Partial<object>) => void;
14
14
  stop: () => void;
15
15
  name: () => string;
16
+ abort: () => void;
16
17
  };
package/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "async-queue-runner",
3
- "version": "0.10.0",
3
+ "version": "0.12.0",
4
4
  "description": "Library to run in parallel extendable queue of tasks",
5
- "type": "module",
6
5
  "scripts": {
7
6
  "compile": "tsc --project ./tsconfig.json",
8
7
  "copy:package:json": "copyfiles ./package.json ./built/ && copyfiles ./_esm/* ./built && copyfiles ./_cjs/* ./built",