@nxtedition/scheduler 3.0.6 → 3.0.8
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 +8 -5
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -104,14 +104,17 @@ export class Scheduler {
|
|
|
104
104
|
}
|
|
105
105
|
const stateBuffer = new SharedArrayBuffer(64)
|
|
106
106
|
const stateView = new Int32Array(stateBuffer)
|
|
107
|
-
Atomics.store(stateView, CONCURRENCY_INDEX, concurrency ??
|
|
107
|
+
Atomics.store(stateView, CONCURRENCY_INDEX, concurrency ?? -1)
|
|
108
108
|
return stateBuffer
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
constructor(opts ) {
|
|
112
112
|
if (opts instanceof SharedArrayBuffer) {
|
|
113
113
|
this.#stateView = new Int32Array(opts)
|
|
114
|
-
this.#concurrency = Atomics.load(this.#stateView, CONCURRENCY_INDEX)
|
|
114
|
+
this.#concurrency = Atomics.load(this.#stateView, CONCURRENCY_INDEX)
|
|
115
|
+
if (this.#concurrency === -1) {
|
|
116
|
+
this.#concurrency = Infinity
|
|
117
|
+
}
|
|
115
118
|
} else {
|
|
116
119
|
this.#concurrency = opts?.concurrency ?? Infinity
|
|
117
120
|
}
|
|
@@ -153,9 +156,9 @@ export class Scheduler {
|
|
|
153
156
|
return
|
|
154
157
|
}
|
|
155
158
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
+
// We use non atomic access here as an optimization and treat the concurrency limit as a soft limit.
|
|
160
|
+
if (this.#stateView[RUNNING_INDEX] < this.#concurrency) {
|
|
161
|
+
Atomics.add(this.#stateView, RUNNING_INDEX, 1)
|
|
159
162
|
this.#running += 1
|
|
160
163
|
fn(opaque)
|
|
161
164
|
return
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxtedition/scheduler",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"rimraf": "^6.1.2",
|
|
29
29
|
"typescript": "^5.9.3"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "12c38fec15bd155797cb1edae372a81061715df3"
|
|
32
32
|
}
|