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 +4 -3
- package/dist/index.d.ts +17 -37
- package/dist/index.js +35 -22
- package/dist/index.js.map +1 -1
- package/dist/mem-store.d.ts +4 -7
- package/dist/mem-store.js +1 -10
- package/dist/mem-store.js.map +1 -1
- package/dist/store.d.ts +9 -0
- package/dist/store.js +3 -0
- package/dist/store.js.map +1 -0
- package/package.json +11 -10
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
|
-
](https://www.npmjs.com/package/timequeue)
|
|
6
|
+
[](https://github.com/fent/timequeue.js/actions/workflows/nodejs.yml)
|
|
6
7
|
[](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.
|
|
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.
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
|
24
|
-
|
|
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:
|
|
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:
|
|
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
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
this.
|
|
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
|
-
|
|
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
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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
|
-
|
|
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":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,mCAAsC;AACtC,4DAAsC;AAatC,MAAa,SAAU,SAAQ,KAAK;CAEnC;AAFD,8BAEC;AAED,MAAqB,SAAU,SAAQ,qBAAY;IAsBjD;;;;;;;;;OASG;IACH,YAAY,MAAc,EAAE,UAAmB,EAAE;QAC/C,KAAK,EAAE,CAAC;QArBV,uCAAuC;QAChC,WAAM,GAAG,CAAC,CAAC;QAElB,4CAA4C;QAC5C,uCAAuC;QAChC,cAAS,GAAG,CAAC,CAAC;QAErB,gCAAgC;QACzB,aAAQ,GAAG,CAAC,CAAC;QAelB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,KAAK,eAAe,CAAC;QAClE,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,CA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AAG,KAAK,CAAC,CAAC;YACxB,CAAC;QACH,CAAC;KAAA;IAED;;;OAGG;IACG,KAAK;;YACT,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;gBACvC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;gBAC5C,IAAI,IAAI,EAAE,CAAC;oBACT,IAAI,CAAC,MAAM,EAAE,CAAC;oBACd,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;oBAE1B,IAAI,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;wBAC3C,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;oBACrB,CAAC;oBACD,OAAO;gBACT,CAAC;YACH,CAAC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,KAAK,CAAC,EAAE,CAAC;gBAC3B,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACrB,CAAC;QACH,CAAC;KAAA;IAED;;;OAGG;IACG,GAAG;;YACP,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;YACzB,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;gBAC7B,YAAY,CAAC,CAAC,CAAC,CAAC;YAClB,CAAC;YACD,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;YAClB,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC;YACnB,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QAClB,CAAC;KAAA;CACF;AAhND,4BAgNC"}
|
package/dist/mem-store.d.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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:
|
|
8
|
-
|
|
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
|
-
|
|
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
|
});
|
package/dist/mem-store.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mem-store.js","sourceRoot":"","sources":["../src/mem-store.ts"],"names":[],"mappings":"
|
|
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"}
|
package/dist/store.d.ts
ADDED
package/dist/store.js
ADDED
|
@@ -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": "
|
|
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 --
|
|
25
|
+
"test:unit": "mocha --require ts-node/register test/*-test.ts"
|
|
24
26
|
},
|
|
25
27
|
"devDependencies": {
|
|
26
|
-
"@
|
|
27
|
-
"@types/
|
|
28
|
-
"@types/
|
|
29
|
-
"mocha": "^
|
|
30
|
-
"nyc": "^
|
|
31
|
-
"
|
|
32
|
-
"
|
|
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"
|