@nxtedition/scheduler 1.0.6 → 1.0.7
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.js +34 -24
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -15,6 +15,7 @@ export class Scheduler {
|
|
|
15
15
|
#running = 0
|
|
16
16
|
#pending = 0
|
|
17
17
|
#counter = 0
|
|
18
|
+
#actived = false
|
|
18
19
|
|
|
19
20
|
#lowQueue = new FixedQueue()
|
|
20
21
|
#normalQueue = new FixedQueue()
|
|
@@ -87,32 +88,41 @@ export class Scheduler {
|
|
|
87
88
|
}
|
|
88
89
|
|
|
89
90
|
#next = () => {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
: this.#counter++
|
|
99
|
-
const fn =
|
|
100
|
-
((counter & 63) === 0 && this.#lowQueue.shift()) ??
|
|
101
|
-
((counter & 15) === 0 && this.#normalQueue.shift()) ??
|
|
102
|
-
this.#highQueue.shift() ??
|
|
103
|
-
this.#normalQueue.shift() ??
|
|
104
|
-
this.#lowQueue.shift()
|
|
105
|
-
|
|
106
|
-
if (!fn) {
|
|
107
|
-
break
|
|
91
|
+
try {
|
|
92
|
+
let running = this.#stateView
|
|
93
|
+
? Atomics.sub(this.#stateView, Scheduler.#RUNNING_INDEX, 1) - 1
|
|
94
|
+
: this.#running - 1
|
|
95
|
+
this.#running -= 1
|
|
96
|
+
|
|
97
|
+
if (this.#actived) {
|
|
98
|
+
return
|
|
108
99
|
}
|
|
109
100
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
101
|
+
this.#actived = true
|
|
102
|
+
while (this.#pending > 0 && (this.#running < 1 || running < this.#concurrency)) {
|
|
103
|
+
const counter = this.#stateView
|
|
104
|
+
? Atomics.add(this.#stateView, Scheduler.#COUNTER_INDEX, 1)
|
|
105
|
+
: this.#counter++
|
|
106
|
+
const fn =
|
|
107
|
+
((counter & 63) === 0 && this.#lowQueue.shift()) ??
|
|
108
|
+
((counter & 15) === 0 && this.#normalQueue.shift()) ??
|
|
109
|
+
this.#highQueue.shift() ??
|
|
110
|
+
this.#normalQueue.shift() ??
|
|
111
|
+
this.#lowQueue.shift()
|
|
112
|
+
|
|
113
|
+
running = this.#stateView
|
|
114
|
+
? Atomics.add(this.#stateView, Scheduler.#RUNNING_INDEX, 1) + 1
|
|
115
|
+
: this.#running + 1
|
|
116
|
+
this.#running += 1
|
|
117
|
+
this.#pending -= 1
|
|
118
|
+
fn(this.#next)
|
|
119
|
+
}
|
|
120
|
+
this.#actived = false
|
|
121
|
+
} catch (err) {
|
|
122
|
+
// Throwing here is undefined behavior...
|
|
123
|
+
queueMicrotask(() => {
|
|
124
|
+
throw new Error('Scheduler task error', { cause: err })
|
|
125
|
+
})
|
|
116
126
|
}
|
|
117
127
|
}
|
|
118
128
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxtedition/scheduler",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -20,5 +20,5 @@
|
|
|
20
20
|
"rimraf": "^6.1.2",
|
|
21
21
|
"typescript": "^5.9.3"
|
|
22
22
|
},
|
|
23
|
-
"gitHead": "
|
|
23
|
+
"gitHead": "8a7862ed029e6ec42bbccd925bf638e7b069cc5e"
|
|
24
24
|
}
|