@nxtedition/scheduler 3.0.1 → 3.0.2
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/lib/index.d.ts +1 -2
- package/lib/index.js +6 -16
- package/package.json +2 -3
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type Priority = -3 | -2 | -1 | 0 | 1 | 2 | 3 | 'lowest' | 'lower' | 'low' | 'normal' | 'high' | 'higher' | 'highest';
|
|
2
|
-
export declare function parsePriority(p:
|
|
2
|
+
export declare function parsePriority(p: string | number): number;
|
|
3
3
|
export declare class Scheduler {
|
|
4
4
|
#private;
|
|
5
5
|
static LOWEST: Priority;
|
|
@@ -16,7 +16,6 @@ export declare class Scheduler {
|
|
|
16
16
|
pending: number;
|
|
17
17
|
queues: {
|
|
18
18
|
count: number;
|
|
19
|
-
age: number;
|
|
20
19
|
}[];
|
|
21
20
|
};
|
|
22
21
|
static makeSharedState(concurrency: number): SharedArrayBuffer;
|
package/lib/index.js
CHANGED
|
@@ -3,16 +3,10 @@ const CONCURRENCY_INDEX = 1
|
|
|
3
3
|
|
|
4
4
|
const maxInt = 2147483647
|
|
5
5
|
|
|
6
|
-
let fastNow = Date.now()
|
|
7
|
-
setInterval(() => {
|
|
8
|
-
fastNow = Date.now()
|
|
9
|
-
}, 1e3).unref()
|
|
10
|
-
|
|
11
6
|
class FastQueue {
|
|
12
7
|
idx = 0
|
|
13
8
|
cnt = 0
|
|
14
|
-
arr
|
|
15
|
-
age = fastNow
|
|
9
|
+
arr = []
|
|
16
10
|
}
|
|
17
11
|
|
|
18
12
|
|
|
@@ -31,7 +25,7 @@ class FastQueue {
|
|
|
31
25
|
|
|
32
26
|
|
|
33
27
|
|
|
34
|
-
export function parsePriority(p
|
|
28
|
+
export function parsePriority(p ) {
|
|
35
29
|
if (typeof p === 'number') {
|
|
36
30
|
// Do nothing...
|
|
37
31
|
} else if (p === 'lowest') {
|
|
@@ -100,7 +94,7 @@ export class Scheduler {
|
|
|
100
94
|
deferred: this.#deferred,
|
|
101
95
|
running: this.#running,
|
|
102
96
|
pending: this.#pending,
|
|
103
|
-
queues: this.#queues.map((q) => ({ count: q.cnt
|
|
97
|
+
queues: this.#queues.map((q) => ({ count: q.cnt })),
|
|
104
98
|
}
|
|
105
99
|
}
|
|
106
100
|
|
|
@@ -134,6 +128,7 @@ export class Scheduler {
|
|
|
134
128
|
try {
|
|
135
129
|
resolve(await fn(o))
|
|
136
130
|
} catch (err) {
|
|
131
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
137
132
|
reject(err)
|
|
138
133
|
} finally {
|
|
139
134
|
this.release()
|
|
@@ -146,7 +141,7 @@ export class Scheduler {
|
|
|
146
141
|
}
|
|
147
142
|
|
|
148
143
|
acquire (fn , priority = Scheduler.NORMAL, opaque ) {
|
|
149
|
-
const p = parsePriority(priority)
|
|
144
|
+
const p = parsePriority(priority)
|
|
150
145
|
const queue = this.#queues[p + 3]
|
|
151
146
|
|
|
152
147
|
if (this.#stateView) {
|
|
@@ -165,10 +160,6 @@ export class Scheduler {
|
|
|
165
160
|
queue.arr.push(fn, opaque)
|
|
166
161
|
queue.cnt += 1
|
|
167
162
|
|
|
168
|
-
if (queue.cnt === 1) {
|
|
169
|
-
queue.age = fastNow
|
|
170
|
-
}
|
|
171
|
-
|
|
172
163
|
this.#deferred += 1
|
|
173
164
|
this.#pending += 1
|
|
174
165
|
}
|
|
@@ -222,10 +213,9 @@ export class Scheduler {
|
|
|
222
213
|
throw new Error('Invariant violation: pending > 0 but no tasks in queues')
|
|
223
214
|
}
|
|
224
215
|
|
|
225
|
-
const fn = queue.arr[queue.idx++]
|
|
216
|
+
const fn = queue.arr[queue.idx++]
|
|
226
217
|
const opaque = queue.arr[queue.idx++]
|
|
227
218
|
queue.cnt -= 1
|
|
228
|
-
queue.age = fastNow
|
|
229
219
|
|
|
230
220
|
if (queue.cnt === 0) {
|
|
231
221
|
queue.idx = 0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxtedition/scheduler",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -19,6 +19,5 @@
|
|
|
19
19
|
"amaroc": "^1.0.1",
|
|
20
20
|
"rimraf": "^6.1.2",
|
|
21
21
|
"typescript": "^5.9.3"
|
|
22
|
-
}
|
|
23
|
-
"gitHead": "c88bafd0c4a7e250d9e4080d9f50a0a0a1a562ac"
|
|
22
|
+
}
|
|
24
23
|
}
|