timequeue 3.0.1 → 4.0.1

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/README.md CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  A queue with custom concurrency and time limits. Inspired by [async/queue](https://caolan.github.io/async/v3/docs.html#queue), but also with variable number of arguments in the worker, events, and with optional time limits.
4
4
 
5
- ![Depfu](https://img.shields.io/depfu/fent/timequeue.js)
5
+ [![npm](https://img.shields.io/npm/v/timequeue)](https://www.npmjs.com/package/timequeue)
6
+ [![Node.js CI](https://github.com/fent/timequeue.js/actions/workflows/nodejs.yml/badge.svg)](https://github.com/fent/timequeue.js/actions/workflows/nodejs.yml)
6
7
  [![codecov](https://codecov.io/gh/fent/timequeue.js/branch/master/graph/badge.svg)](https://codecov.io/gh/fent/timequeue.js)
7
8
 
8
9
  # Usage
@@ -63,7 +64,7 @@ Creates a new instance of a queue. Worker must be a function with a callback for
63
64
 
64
65
  // You can pass a custom store to share tasks between several queues.
65
66
  // Default is MemoryStore from `src/mem-store.ts`.
66
- // Look at `example/redis-store.js` for an example that saves tasks onto redis.
67
+ // Look at `example/redis-store.ts` for an example that saves tasks onto redis.
67
68
  , store: MemoryStore
68
69
  }
69
70
  ```
@@ -84,7 +85,7 @@ Pushes a new task to the queue. Any number of arguments can be given. An optiona
84
85
 
85
86
  If the queue is full, pushed tasks will be ignored.
86
87
 
87
- ### async TimeQueue#store.getQueued()
88
+ ### async TimeQueue#store.getQueueLen()
88
89
  How many tasks are currently in the queue.
89
90
 
90
91
  ### TimeQueue#isFull()
package/dist/index.d.ts CHANGED
@@ -1,48 +1,29 @@
1
- /// <reference types="node" />
2
1
  import { EventEmitter } from 'events';
3
- declare namespace TimeQueue {
4
- type Worker = (...args: any[]) => void | Promise<any>;
5
- interface Options {
6
- concurrency?: number;
7
- every?: number;
8
- maxQueued?: number;
9
- timeout?: number;
10
- store?: Store;
11
- }
12
- interface TaskError extends Error {
13
- args: any[];
14
- }
15
- interface Store {
16
- isEmpty: () => Promise<boolean>;
17
- getQueued: () => Promise<number>;
18
- getNextTask: () => Promise<any[]>;
19
- pushTask: (...args: any[]) => void;
20
- clear: () => void;
21
- }
2
+ import type { Store } from './store';
3
+ export type { Store, StoreOptions } from './store';
4
+ export type Worker = (...args: any[]) => void | Promise<any>;
5
+ export interface Options {
6
+ concurrency?: number;
7
+ every?: number;
8
+ maxQueued?: number;
9
+ timeout?: number;
10
+ store?: Store;
22
11
  }
23
- declare class TimeQueue extends EventEmitter {
24
- worker: TimeQueue.Worker;
12
+ export declare class TaskError extends Error {
13
+ args: any[];
14
+ }
15
+ export default class TimeQueue extends EventEmitter {
16
+ worker: Worker;
25
17
  concurrency: number;
26
18
  every: number;
27
19
  maxQueued: number;
28
20
  timeout: number;
29
21
  private _isWorkerAsync;
30
22
  private _timers;
31
- store: TimeQueue.Store;
23
+ store: Store;
32
24
  active: number;
33
25
  intransit: number;
34
26
  finished: number;
35
- static TaskError: {
36
- new (message?: string): {
37
- args: any[];
38
- name: string;
39
- message: string;
40
- stack?: string;
41
- };
42
- captureStackTrace(targetObject: object, constructorOpt?: Function): void;
43
- prepareStackTrace?: (err: Error, stackTraces: NodeJS.CallSite[]) => any;
44
- stackTraceLimit: number;
45
- };
46
27
  /**
47
28
  * @constructor
48
29
  * @extends {EventEmitter}
@@ -53,7 +34,7 @@ declare class TimeQueue extends EventEmitter {
53
34
  * @param {number?} options.maxQueued
54
35
  * @param {number?} options.timeout
55
36
  */
56
- constructor(worker: TimeQueue.Worker, options?: TimeQueue.Options);
37
+ constructor(worker: Worker, options?: Options);
57
38
  /**
58
39
  * Pushes a task onto the queue.
59
40
  *
@@ -77,6 +58,5 @@ declare class TimeQueue extends EventEmitter {
77
58
  * Empties the queue and kills the timers.
78
59
  * Active tasks will still be completed.
79
60
  */
80
- die(): void;
61
+ die(): Promise<void>;
81
62
  }
82
- export = TimeQueue;
package/dist/index.js CHANGED
@@ -11,8 +11,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.TaskError = void 0;
14
16
  const events_1 = require("events");
15
17
  const mem_store_1 = __importDefault(require("./mem-store"));
18
+ class TaskError extends Error {
19
+ }
20
+ exports.TaskError = TaskError;
16
21
  class TimeQueue extends events_1.EventEmitter {
17
22
  /**
18
23
  * @constructor
@@ -34,12 +39,13 @@ class TimeQueue extends events_1.EventEmitter {
34
39
  // How many tasks have finished.
35
40
  this.finished = 0;
36
41
  this.worker = worker;
37
- this._isWorkerAsync = worker.constructor.name == 'AsyncFunction';
42
+ this._isWorkerAsync = worker.constructor.name === 'AsyncFunction';
38
43
  this.concurrency = options.concurrency || 1;
39
44
  this.every = options.every || 0;
40
45
  this.maxQueued = options.maxQueued || Infinity;
41
46
  this.timeout = options.timeout || 0;
42
- this.store = options.store || new mem_store_1.default({ maxQueued: this.maxQueued });
47
+ this.store =
48
+ options.store || new mem_store_1.default({ maxQueued: this.maxQueued });
43
49
  this._timers = [];
44
50
  }
45
51
  /**
@@ -52,8 +58,8 @@ class TimeQueue extends events_1.EventEmitter {
52
58
  push(...args) {
53
59
  return __awaiter(this, void 0, void 0, function* () {
54
60
  // Returns a promise when no `callback` is given.
55
- if (this._isWorkerAsync && args.length === this.worker.length ||
56
- !this._isWorkerAsync && args.length < this.worker.length) {
61
+ if ((this._isWorkerAsync && args.length === this.worker.length) ||
62
+ (!this._isWorkerAsync && args.length < this.worker.length)) {
57
63
  return new Promise((resolve, reject) => {
58
64
  // Add any missing arguments.
59
65
  if (!this._isWorkerAsync) {
@@ -61,6 +67,8 @@ class TimeQueue extends events_1.EventEmitter {
61
67
  args.push(undefined);
62
68
  }
63
69
  }
70
+ // Calling from the prototype directly fixes an infinute loop bug that
71
+ // occurs when this method is overwritten by a child class.
64
72
  TimeQueue.prototype.push.call(this, ...args, (err, results) => {
65
73
  if (err)
66
74
  return reject(err);
@@ -90,7 +98,7 @@ class TimeQueue extends events_1.EventEmitter {
90
98
  return __awaiter(this, void 0, void 0, function* () {
91
99
  const callback = args.pop();
92
100
  let finished = false;
93
- let every = ~~this.every;
101
+ const every = ~~this.every;
94
102
  let tookLongerThanEvery;
95
103
  if (every) {
96
104
  tookLongerThanEvery = false;
@@ -108,7 +116,7 @@ class TimeQueue extends events_1.EventEmitter {
108
116
  // If `timeout` option is set, set a timeout to check the task doesn't lag.
109
117
  let taskTimedOut = false;
110
118
  let callbackCalled = false;
111
- let timeout = ~~this.timeout;
119
+ const timeout = ~~this.timeout;
112
120
  let tid;
113
121
  const taskCallback = (err, result) => {
114
122
  // If this task has timed out, and the callback is called again
@@ -134,7 +142,7 @@ class TimeQueue extends events_1.EventEmitter {
134
142
  };
135
143
  if (timeout) {
136
144
  tid = setTimeout(() => {
137
- const err = new TimeQueue.TaskError('Task timed out');
145
+ const err = new TaskError('Task timed out');
138
146
  err.args = args;
139
147
  taskCallback(err);
140
148
  taskTimedOut = true;
@@ -163,15 +171,18 @@ class TimeQueue extends events_1.EventEmitter {
163
171
  */
164
172
  _next() {
165
173
  return __awaiter(this, void 0, void 0, function* () {
166
- let task;
167
- if (this.intransit <= this.concurrency && (task = yield this.store.getNextTask())) {
168
- this.active++;
169
- yield this._process(task);
170
- if (yield this.store.isEmpty()) {
171
- this.emit('empty');
174
+ if (this.intransit <= this.concurrency) {
175
+ const task = yield this.store.getNextTask();
176
+ if (task) {
177
+ this.active++;
178
+ yield this._process(task);
179
+ if ((yield this.store.getQueueLen()) === 0) {
180
+ this.emit('empty');
181
+ }
182
+ return;
172
183
  }
173
184
  }
174
- else if (--this.intransit === 0) {
185
+ if (--this.intransit === 0) {
175
186
  this.emit('drain');
176
187
  }
177
188
  });
@@ -181,14 +192,16 @@ class TimeQueue extends events_1.EventEmitter {
181
192
  * Active tasks will still be completed.
182
193
  */
183
194
  die() {
184
- this.store.clear();
185
- this._timers.forEach(clearTimeout);
186
- this._timers = [];
187
- this.intransit = 0;
188
- this.active = 0;
195
+ return __awaiter(this, void 0, void 0, function* () {
196
+ yield this.store.clear();
197
+ for (const t of this._timers) {
198
+ clearTimeout(t);
199
+ }
200
+ this._timers = [];
201
+ this.intransit = 0;
202
+ this.active = 0;
203
+ });
189
204
  }
190
205
  }
191
- TimeQueue.TaskError = class TaskError extends Error {
192
- };
193
- module.exports = TimeQueue;
206
+ exports.default = TimeQueue;
194
207
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,mCAAsC;AACtC,4DAAsC;AAuBtC,MAAM,SAAU,SAAQ,qBAAY;IA0BlC;;;;;;;;;OASG;IACH,YAAY,MAAwB,EAAE,UAA6B,EAAE;QACnE,KAAK,EAAE,CAAC;QAzBV,uCAAuC;QAChC,WAAM,GAAG,CAAC,CAAC;QAElB,4CAA4C;QAC5C,uCAAuC;QAChC,cAAS,GAAG,CAAC,CAAC;QAErB,gCAAgC;QACzB,aAAQ,GAAG,CAAC,CAAC;QAmBlB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,IAAI,eAAe,CAAC;QACjE,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,CAAC,CAAC;QAC5C,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC;QAChC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,QAAQ,CAAC;QAC/C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,CAAC,CAAC;QACpC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,IAAI,mBAAW,CAAC,EAAE,SAAS,EAA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
2
- maxQueued?: number;
3
- }
4
- export default class MemoryStore {
1
+ import type { Store, StoreOptions } from './store';
2
+ export default class MemoryStore implements Store {
5
3
  maxQueued: number;
6
4
  private _queue;
7
- constructor(options: Options);
8
- isEmpty(): Promise<boolean>;
9
- getQueued(): Promise<number>;
5
+ constructor(options: StoreOptions);
6
+ getQueueLen(): Promise<number>;
10
7
  getNextTask(): Promise<any[]>;
11
8
  pushTask(args: any[]): Promise<void>;
12
9
  clear(): Promise<void>;
package/dist/mem-store.js CHANGED
@@ -9,21 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Options = void 0;
13
- class Options {
14
- }
15
- exports.Options = Options;
16
12
  class MemoryStore {
17
13
  constructor(options) {
18
14
  this.maxQueued = options.maxQueued;
19
15
  this._queue = [];
20
16
  }
21
- isEmpty() {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- return this._queue.length === 0;
24
- });
25
- }
26
- getQueued() {
17
+ getQueueLen() {
27
18
  return __awaiter(this, void 0, void 0, function* () {
28
19
  return this._queue.length;
29
20
  });
@@ -1 +1 @@
1
- {"version":3,"file":"mem-store.js","sourceRoot":"","sources":["../src/mem-store.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,MAAa,OAAO;CAEnB;AAFD,0BAEC;AACD,MAAqB,WAAW;IAG9B,YAAY,OAAgB;QAC1B,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;IACnB,CAAC;IACK,OAAO;;YACX,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC;QAClC,CAAC;KAAA;IACK,SAAS;;YACb,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;QAC5B,CAAC;KAAA;IACK,WAAW;;YACf,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAC7B,CAAC;KAAA;IACK,QAAQ,CAAC,IAAW;;YACxB,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE;gBACvC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aACxB;QACH,CAAC;KAAA;IACK,KAAK;;YACT,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACnB,CAAC;KAAA;CACF;AAxBD,8BAwBC"}
1
+ {"version":3,"file":"mem-store.js","sourceRoot":"","sources":["../src/mem-store.ts"],"names":[],"mappings":";;;;;;;;;;;AAEA,MAAqB,WAAW;IAG9B,YAAY,OAAqB;QAC/B,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;IACnB,CAAC;IACK,WAAW;;YACf,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;QAC5B,CAAC;KAAA;IACK,WAAW;;YACf,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAC7B,CAAC;KAAA;IACK,QAAQ,CAAC,IAAW;;YACxB,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;gBACxC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACzB,CAAC;QACH,CAAC;KAAA;IACK,KAAK;;YACT,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACnB,CAAC;KAAA;CACF;AArBD,8BAqBC"}
@@ -0,0 +1,9 @@
1
+ export interface StoreOptions {
2
+ maxQueued?: number;
3
+ }
4
+ export interface Store {
5
+ getQueueLen(): Promise<number>;
6
+ getNextTask(): Promise<any[]>;
7
+ pushTask(...args: any[]): Promise<void>;
8
+ clear(): Promise<void>;
9
+ }
package/dist/store.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "flow",
7
7
  "time"
8
8
  ],
9
- "version": "3.0.1",
9
+ "version": "4.0.1",
10
10
  "repository": {
11
11
  "type": "git",
12
12
  "url": "git://github.com/fent/timequeue.js.git"
@@ -19,18 +19,19 @@
19
19
  "scripts": {
20
20
  "prepare": "tsc -p tsconfig.build.json",
21
21
  "build": "tsc -p tsconfig.build.json",
22
+ "lint": "biome check .",
23
+ "lint:fix": "biome check --write .",
22
24
  "test": "nyc --extension .ts --reporter=lcov --reporter=text-summary npm run test:unit",
23
- "test:unit": "mocha -- --require ts-node/register test/*-test.ts"
25
+ "test:unit": "mocha --require ts-node/register test/*-test.ts"
24
26
  },
25
27
  "devDependencies": {
26
- "@types/mocha": "^7.0.0",
27
- "@types/node": "^13.1.6",
28
- "@types/sinon": "^9.0.8",
29
- "mocha": "^7.0.1",
30
- "nyc": "^15.0.0",
31
- "sinon": "^9.0.0",
32
- "ts-node": "^10.4.0",
33
- "typescript": "^4.5.4"
28
+ "@biomejs/biome": "2.5.15",
29
+ "@types/mocha": "^10.0.10",
30
+ "@types/node": "^20.1.2",
31
+ "mocha": "^12.0.3",
32
+ "nyc": "^18.0.0",
33
+ "ts-node": "^10.9.2",
34
+ "typescript": "^5.6.3"
34
35
  },
35
36
  "engines": {
36
37
  "node": ">=10"