@balena/promise-queue 1.3.2 → 1.3.3
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/.github/workflows/flowzone.yml +18 -0
- package/.husky/pre-commit +1 -0
- package/.versionbot/CHANGELOG.yml +28 -17
- package/CHANGELOG.md +5 -0
- package/out/index.d.ts +3 -8
- package/out/index.js +8 -9
- package/out/index.js.map +1 -1
- package/package.json +11 -19
- package/src/index.ts +7 -9
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
name: Flowzone
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
types: [opened, synchronize, closed]
|
|
6
|
+
branches: [main, master]
|
|
7
|
+
pull_request_target:
|
|
8
|
+
types: [opened, synchronize, closed]
|
|
9
|
+
branches: [main, master]
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
flowzone:
|
|
13
|
+
name: Flowzone
|
|
14
|
+
uses: product-os/flowzone/.github/workflows/flowzone.yml@master
|
|
15
|
+
if: |
|
|
16
|
+
(github.event.pull_request.head.repo.full_name == github.repository && github.event_name == 'pull_request') ||
|
|
17
|
+
(github.event.pull_request.head.repo.full_name != github.repository && github.event_name == 'pull_request_target')
|
|
18
|
+
secrets: inherit
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
npx --no lint-staged
|
|
@@ -1,17 +1,28 @@
|
|
|
1
|
+
- commits:
|
|
2
|
+
- subject: Update eventemitter3 to 5.x
|
|
3
|
+
hash: f63f3c3b8af41502724d10028b1eb324f5d3f4e1
|
|
4
|
+
body: ""
|
|
5
|
+
footer:
|
|
6
|
+
Change-type: patch
|
|
7
|
+
change-type: patch
|
|
8
|
+
author: Pagan Gazzard
|
|
9
|
+
version: 1.3.3
|
|
10
|
+
title: ""
|
|
11
|
+
date: 2025-10-09T12:33:20.997Z
|
|
1
12
|
- commits:
|
|
2
13
|
- subject: Fix checking for timed out items
|
|
3
14
|
hash: d88adf26c1f53c5e2064879f37baa4a5c5ba9e02
|
|
4
|
-
body:
|
|
15
|
+
body: ""
|
|
5
16
|
footer:
|
|
6
17
|
Change-type: patch
|
|
7
18
|
change-type: patch
|
|
8
19
|
author: Pagan Gazzard
|
|
9
20
|
version: 1.3.2
|
|
10
|
-
date: 2021-10-19T19:
|
|
21
|
+
date: 2021-10-19T19:20:12.523Z
|
|
11
22
|
- commits:
|
|
12
23
|
- subject: Update dependencies
|
|
13
24
|
hash: 9f367d50fb063d6bd6b7431d87510dbf1f8a7eaf
|
|
14
|
-
body:
|
|
25
|
+
body: ""
|
|
15
26
|
footer:
|
|
16
27
|
Change-type: patch
|
|
17
28
|
change-type: patch
|
|
@@ -21,7 +32,7 @@
|
|
|
21
32
|
- commits:
|
|
22
33
|
- subject: emit a single metric event for mass timeouts
|
|
23
34
|
hash: b1e64f5f70a23cc94707c971e0a0bb4d58e9fe96
|
|
24
|
-
body:
|
|
35
|
+
body: ""
|
|
25
36
|
footer:
|
|
26
37
|
Change-type: minor
|
|
27
38
|
change-type: minor
|
|
@@ -33,7 +44,7 @@
|
|
|
33
44
|
- commits:
|
|
34
45
|
- subject: Revert use of bigint which changed the type of the emitted queueTime
|
|
35
46
|
hash: 7b72193829f0d9214ef68205d668944eab9df9d6
|
|
36
|
-
body:
|
|
47
|
+
body: ""
|
|
37
48
|
footer:
|
|
38
49
|
Change-type: patch
|
|
39
50
|
change-type: patch
|
|
@@ -43,7 +54,7 @@
|
|
|
43
54
|
- commits:
|
|
44
55
|
- subject: Remove all queued items if none are valid
|
|
45
56
|
hash: f34eb44ab9c3e6eaf472487744d8bca34ac09a13
|
|
46
|
-
body:
|
|
57
|
+
body: ""
|
|
47
58
|
footer:
|
|
48
59
|
Change-type: patch
|
|
49
60
|
change-type: patch
|
|
@@ -53,7 +64,7 @@
|
|
|
53
64
|
- commits:
|
|
54
65
|
- subject: use process.hrtime.bigint
|
|
55
66
|
hash: 7ba48d856386d12fa06ecaf3ca2a4ec81f9ec962
|
|
56
|
-
body:
|
|
67
|
+
body: ""
|
|
57
68
|
footer:
|
|
58
69
|
Change-type: patch
|
|
59
70
|
change-type: patch
|
|
@@ -65,7 +76,7 @@
|
|
|
65
76
|
- commits:
|
|
66
77
|
- subject: Add .versionbot/CHANGELOG.yml for downstream changelogs
|
|
67
78
|
hash: 52a2cbbe9c7fe966c72f69b39199e69657b4a6de
|
|
68
|
-
body:
|
|
79
|
+
body: ""
|
|
69
80
|
footer:
|
|
70
81
|
Change-type: patch
|
|
71
82
|
change-type: patch
|
|
@@ -74,40 +85,40 @@
|
|
|
74
85
|
date: 2019-05-09T14:00:31.452Z
|
|
75
86
|
- commits:
|
|
76
87
|
- author: dt-rush
|
|
77
|
-
body:
|
|
88
|
+
body: ""
|
|
78
89
|
footers:
|
|
79
90
|
change-type: minor
|
|
80
|
-
connects-to:
|
|
91
|
+
connects-to: "#6"
|
|
81
92
|
signed-off-by: Nick Payne <nickp@balena.io>
|
|
82
93
|
hash: a7b4eda7739df2fcbe8c6ebe179655d95d36cd46
|
|
83
94
|
subject: made queueLength and inFlight metrics more reliable/useful
|
|
84
|
-
date:
|
|
95
|
+
date: 2019-05-08T16:56:07Z
|
|
85
96
|
version: 1.2.0
|
|
86
97
|
- commits:
|
|
87
98
|
- author: Pagan Gazzard
|
|
88
|
-
body:
|
|
99
|
+
body: ""
|
|
89
100
|
footers:
|
|
90
101
|
change-type: patch
|
|
91
102
|
hash: 1164046db5ef9e72745e0085e9b5b1224a1cf135
|
|
92
103
|
subject: Switch to a `setInterval` for enforcing maxAge for better performance
|
|
93
|
-
date:
|
|
104
|
+
date: 2019-04-12T13:33:07Z
|
|
94
105
|
version: 1.1.1
|
|
95
106
|
- commits:
|
|
96
107
|
- author: dt-rush
|
|
97
|
-
body:
|
|
108
|
+
body: ""
|
|
98
109
|
footers:
|
|
99
110
|
change-type: minor
|
|
100
111
|
signed-off-by: Nick Payne <nickp@balena.io>
|
|
101
112
|
hash: 7ab24f81e0e68cf7436a4e1206132f90b710e332
|
|
102
113
|
subject: expose metrics via EventEmitter
|
|
103
|
-
date:
|
|
114
|
+
date: 2019-03-13T19:31:18Z
|
|
104
115
|
version: 1.1.0
|
|
105
116
|
- commits:
|
|
106
117
|
- author: Pagan Gazzard
|
|
107
|
-
body:
|
|
118
|
+
body: ""
|
|
108
119
|
footers:
|
|
109
120
|
change-type: major
|
|
110
121
|
hash: 78071037d732c1a79a70eede5077266d343f36e9
|
|
111
122
|
subject: Initial release
|
|
112
|
-
date:
|
|
123
|
+
date: 2019-03-08T10:15:02Z
|
|
113
124
|
version: 1.0.0
|
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file
|
|
|
4
4
|
automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY!
|
|
5
5
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
|
6
6
|
|
|
7
|
+
# v1.3.3
|
|
8
|
+
## (2025-10-09)
|
|
9
|
+
|
|
10
|
+
* Update eventemitter3 to 5.x [Pagan Gazzard]
|
|
11
|
+
|
|
7
12
|
# v1.3.2
|
|
8
13
|
## (2021-10-19)
|
|
9
14
|
|
package/out/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TypedError } from 'typed-error';
|
|
2
|
-
import
|
|
2
|
+
import { EventEmitter } from 'eventemitter3';
|
|
3
3
|
export declare class PromiseQueueError extends TypedError {
|
|
4
4
|
}
|
|
5
5
|
export declare class MaxSizeExceededError extends PromiseQueueError {
|
|
@@ -13,7 +13,7 @@ export declare class PromiseQueue {
|
|
|
13
13
|
private concurrency;
|
|
14
14
|
private maxSize;
|
|
15
15
|
private order;
|
|
16
|
-
metrics: EventEmitter
|
|
16
|
+
metrics: EventEmitter<string | symbol, any>;
|
|
17
17
|
constructor({ concurrency, maxSize, maxAge, order, }?: {
|
|
18
18
|
concurrency?: PromiseQueue['concurrency'];
|
|
19
19
|
maxSize?: PromiseQueue['maxSize'];
|
|
@@ -23,9 +23,4 @@ export declare class PromiseQueue {
|
|
|
23
23
|
private run;
|
|
24
24
|
add<T>(fn: () => T | PromiseLike<T>): Promise<T>;
|
|
25
25
|
}
|
|
26
|
-
export declare const createKeyedPromiseQueue: (
|
|
27
|
-
concurrency?: number | undefined;
|
|
28
|
-
maxSize?: number | undefined;
|
|
29
|
-
maxAge?: number | undefined;
|
|
30
|
-
order?: "fifo" | "lifo" | undefined;
|
|
31
|
-
} | undefined) => <T>(key: string, fn: () => T | PromiseLike<T>) => Promise<T>;
|
|
26
|
+
export declare const createKeyedPromiseQueue: (...args: ConstructorParameters<typeof PromiseQueue>) => <T>(key: string, fn: () => T | PromiseLike<T>) => Promise<T>;
|
package/out/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createKeyedPromiseQueue = exports.PromiseQueue = exports.TimeoutError = exports.MaxSizeExceededError = exports.PromiseQueueError = void 0;
|
|
4
4
|
const typed_error_1 = require("typed-error");
|
|
5
|
-
const
|
|
5
|
+
const eventemitter3_1 = require("eventemitter3");
|
|
6
6
|
class PromiseQueueError extends typed_error_1.TypedError {
|
|
7
7
|
}
|
|
8
8
|
exports.PromiseQueueError = PromiseQueueError;
|
|
@@ -20,7 +20,7 @@ class PromiseQueue {
|
|
|
20
20
|
constructor({ concurrency = 1, maxSize = 0, maxAge = 0, order = 'fifo', } = {}) {
|
|
21
21
|
this.queue = [];
|
|
22
22
|
this.inFlight = 0;
|
|
23
|
-
this.metrics = new EventEmitter();
|
|
23
|
+
this.metrics = new eventemitter3_1.EventEmitter();
|
|
24
24
|
if (maxSize < 0) {
|
|
25
25
|
throw new Error('maxSize must be positive');
|
|
26
26
|
}
|
|
@@ -57,7 +57,7 @@ class PromiseQueue {
|
|
|
57
57
|
const timeoutError = new TimeoutError();
|
|
58
58
|
this.metrics.emit('timeout', timedOutFns.length);
|
|
59
59
|
timedOutFns.forEach((timedOutFn) => {
|
|
60
|
-
timedOutFn(timeoutError);
|
|
60
|
+
void timedOutFn(timeoutError);
|
|
61
61
|
});
|
|
62
62
|
}, 1000);
|
|
63
63
|
}
|
|
@@ -85,7 +85,7 @@ class PromiseQueue {
|
|
|
85
85
|
if (this.order === 'lifo') {
|
|
86
86
|
const evictedFn = this.queue.shift();
|
|
87
87
|
this.metrics.emit('queueLength', this.queue.length);
|
|
88
|
-
evictedFn(err);
|
|
88
|
+
void evictedFn(err);
|
|
89
89
|
}
|
|
90
90
|
else {
|
|
91
91
|
reject(err);
|
|
@@ -104,8 +104,8 @@ class PromiseQueue {
|
|
|
104
104
|
const result = await fn();
|
|
105
105
|
resolve(result);
|
|
106
106
|
}
|
|
107
|
-
catch (
|
|
108
|
-
reject(
|
|
107
|
+
catch (err) {
|
|
108
|
+
reject(err);
|
|
109
109
|
}
|
|
110
110
|
finally {
|
|
111
111
|
this.metrics.emit('serviceTime', durationSince(serviceStartTime));
|
|
@@ -125,9 +125,8 @@ exports.PromiseQueue = PromiseQueue;
|
|
|
125
125
|
const createKeyedPromiseQueue = (...args) => {
|
|
126
126
|
const queues = {};
|
|
127
127
|
return (key, fn) => {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
128
|
+
var _a;
|
|
129
|
+
(_a = queues[key]) !== null && _a !== void 0 ? _a : (queues[key] = new PromiseQueue(...args));
|
|
131
130
|
return queues[key].add(fn);
|
|
132
131
|
};
|
|
133
132
|
};
|
package/out/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,6CAAyC;AACzC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,6CAAyC;AACzC,iDAA6C;AAE7C,MAAa,iBAAkB,SAAQ,wBAAU;CAAG;AAApD,8CAAoD;AACpD,MAAa,oBAAqB,SAAQ,iBAAiB;CAAG;AAA9D,oDAA8D;AA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AAtID,oCAsIC;AAEM,MAAM,uBAAuB,GAAG,CACtC,GAAG,IAAgD,EAClD,EAAE;IACH,MAAM,MAAM,GAER,EAAE,CAAC;IAEP,OAAO,CAAI,GAAW,EAAE,EAA4B,EAAc,EAAE;;QACnE,MAAA,MAAM,CAAC,GAAG,qCAAV,MAAM,CAAC,GAAG,IAAM,IAAI,YAAY,CAAC,GAAG,IAAI,CAAC,EAAC;QAC1C,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC5B,CAAC,CAAC;AACH,CAAC,CAAC;AAXW,QAAA,uBAAuB,2BAWlC"}
|
package/package.json
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@balena/promise-queue",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.3",
|
|
4
4
|
"description": "Queue sync or async functions with max concurrency, max size, max age, and fifo/lifo ordering",
|
|
5
5
|
"author": "Pagan Gazzard <page@balena.io>",
|
|
6
6
|
"main": "out/index.js",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"types": "out/index.d.ts",
|
|
9
9
|
"scripts": {
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"prepare": "npm run build",
|
|
10
|
+
"prepack": "npm run build",
|
|
11
|
+
"prepare": "node -e \"try { (await import('husky')).default() } catch (e) { if (e.code !== 'ERR_MODULE_NOT_FOUND') throw e }\" --input-type module",
|
|
13
12
|
"build": "npx tsc",
|
|
14
13
|
"lint": "balena-lint src/ && tsc --noEmit",
|
|
15
14
|
"test": "npm run lint",
|
|
16
|
-
"
|
|
15
|
+
"lint-fix": "balena-lint --fix src/"
|
|
17
16
|
},
|
|
18
17
|
"homepage": "https://github.com/balena-io-modules/promise-queue",
|
|
19
18
|
"repository": {
|
|
@@ -24,29 +23,22 @@
|
|
|
24
23
|
"url": "https://github.com/balena-io-modules/promise-queue/issues"
|
|
25
24
|
},
|
|
26
25
|
"dependencies": {
|
|
27
|
-
"eventemitter3": "^
|
|
26
|
+
"eventemitter3": "^5.0.1",
|
|
28
27
|
"typed-error": "^3.2.1"
|
|
29
28
|
},
|
|
30
29
|
"devDependencies": {
|
|
31
|
-
"@balena/lint": "^
|
|
30
|
+
"@balena/lint": "^9.3.8",
|
|
32
31
|
"@types/node": "^10.17.60",
|
|
33
|
-
"husky": "^
|
|
34
|
-
"lint-staged": "^
|
|
35
|
-
"
|
|
36
|
-
"typescript": "^4.4.4"
|
|
37
|
-
},
|
|
38
|
-
"husky": {
|
|
39
|
-
"hooks": {
|
|
40
|
-
"pre-commit": "lint-staged",
|
|
41
|
-
"pre-push": "npm run lint"
|
|
42
|
-
}
|
|
32
|
+
"husky": "^9.1.7",
|
|
33
|
+
"lint-staged": "^16.2.3",
|
|
34
|
+
"typescript": "^5.9.3"
|
|
43
35
|
},
|
|
44
36
|
"lint-staged": {
|
|
45
|
-
"
|
|
37
|
+
"*.ts": [
|
|
46
38
|
"balena-lint --fix"
|
|
47
39
|
]
|
|
48
40
|
},
|
|
49
41
|
"versionist": {
|
|
50
|
-
"publishedAt": "
|
|
42
|
+
"publishedAt": "2025-10-09T12:33:21.035Z"
|
|
51
43
|
}
|
|
52
44
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TypedError } from 'typed-error';
|
|
2
|
-
import
|
|
2
|
+
import { EventEmitter } from 'eventemitter3';
|
|
3
3
|
|
|
4
4
|
export class PromiseQueueError extends TypedError {}
|
|
5
5
|
export class MaxSizeExceededError extends PromiseQueueError {}
|
|
@@ -21,7 +21,7 @@ export class PromiseQueue {
|
|
|
21
21
|
private concurrency: number;
|
|
22
22
|
private maxSize: number;
|
|
23
23
|
private order: 'fifo' | 'lifo';
|
|
24
|
-
public metrics
|
|
24
|
+
public metrics = new EventEmitter();
|
|
25
25
|
|
|
26
26
|
constructor({
|
|
27
27
|
concurrency = 1,
|
|
@@ -79,7 +79,7 @@ export class PromiseQueue {
|
|
|
79
79
|
const timeoutError = new TimeoutError();
|
|
80
80
|
this.metrics.emit('timeout', timedOutFns.length);
|
|
81
81
|
timedOutFns.forEach((timedOutFn) => {
|
|
82
|
-
timedOutFn(timeoutError);
|
|
82
|
+
void timedOutFn(timeoutError);
|
|
83
83
|
});
|
|
84
84
|
}, 1000);
|
|
85
85
|
}
|
|
@@ -109,7 +109,7 @@ export class PromiseQueue {
|
|
|
109
109
|
const evictedFn = this.queue.shift()!;
|
|
110
110
|
this.metrics.emit('queueLength', this.queue.length);
|
|
111
111
|
// Make sure the evicted request receives the correct error to respond with
|
|
112
|
-
evictedFn(err);
|
|
112
|
+
void evictedFn(err);
|
|
113
113
|
} else {
|
|
114
114
|
// If we're in fifo (default) mode we can skip wrapping/adding the fn altogether
|
|
115
115
|
reject(err);
|
|
@@ -128,8 +128,8 @@ export class PromiseQueue {
|
|
|
128
128
|
this.metrics.emit('dequeue');
|
|
129
129
|
const result = await fn();
|
|
130
130
|
resolve(result);
|
|
131
|
-
} catch (
|
|
132
|
-
reject(
|
|
131
|
+
} catch (err) {
|
|
132
|
+
reject(err as Error);
|
|
133
133
|
} finally {
|
|
134
134
|
this.metrics.emit('serviceTime', durationSince(serviceStartTime));
|
|
135
135
|
this.metrics.emit('latency', durationSince(arrivalTime));
|
|
@@ -154,9 +154,7 @@ export const createKeyedPromiseQueue = (
|
|
|
154
154
|
} = {};
|
|
155
155
|
|
|
156
156
|
return <T>(key: string, fn: () => T | PromiseLike<T>): Promise<T> => {
|
|
157
|
-
|
|
158
|
-
queues[key] = new PromiseQueue(...args);
|
|
159
|
-
}
|
|
157
|
+
queues[key] ??= new PromiseQueue(...args);
|
|
160
158
|
return queues[key].add(fn);
|
|
161
159
|
};
|
|
162
160
|
};
|