@nxtedition/lib 23.16.0 → 23.16.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/package.json +1 -1
- package/yield.js +16 -13
package/package.json
CHANGED
package/yield.js
CHANGED
|
@@ -4,7 +4,8 @@ const yieldQueue = new FixedQueue()
|
|
|
4
4
|
const yieldSchedule = globalThis.setImmediate ?? ((fn) => setTimeout(fn, 0))
|
|
5
5
|
|
|
6
6
|
let yieldTimeout = 40
|
|
7
|
-
let
|
|
7
|
+
let yieldActive = false
|
|
8
|
+
let yieldScheduled = false
|
|
8
9
|
let yieldTime = performance.now()
|
|
9
10
|
|
|
10
11
|
export function setYieldTimeout(timeout) {
|
|
@@ -15,7 +16,10 @@ export function setYieldTimeout(timeout) {
|
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
export function shouldYield() {
|
|
18
|
-
|
|
19
|
+
if (!yieldActive && performance.now() - yieldTime >= yieldTimeout) {
|
|
20
|
+
yieldActive = true
|
|
21
|
+
}
|
|
22
|
+
return yieldActive
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
export function maybeYield(callback) {
|
|
@@ -23,12 +27,16 @@ export function maybeYield(callback) {
|
|
|
23
27
|
throw new TypeError('callback must be a function')
|
|
24
28
|
}
|
|
25
29
|
|
|
26
|
-
|
|
30
|
+
if (shouldYield()) {
|
|
31
|
+
doYield(callback)
|
|
32
|
+
} else if (callback != null) {
|
|
33
|
+
callback(null)
|
|
34
|
+
}
|
|
27
35
|
}
|
|
28
36
|
|
|
29
37
|
export function doYield(callback) {
|
|
30
|
-
if (
|
|
31
|
-
|
|
38
|
+
if (!yieldScheduled) {
|
|
39
|
+
yieldScheduled = true
|
|
32
40
|
yieldSchedule(dispatchYield)
|
|
33
41
|
}
|
|
34
42
|
|
|
@@ -42,24 +50,19 @@ export function doYield(callback) {
|
|
|
42
50
|
}
|
|
43
51
|
|
|
44
52
|
function dispatchYield() {
|
|
45
|
-
if (yieldState === 2) {
|
|
46
|
-
return
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
yieldState = 2
|
|
50
53
|
yieldTime = performance.now()
|
|
54
|
+
yieldActive = false
|
|
51
55
|
|
|
52
56
|
while (!yieldQueue.isEmpty()) {
|
|
53
57
|
const resolve = yieldQueue.shift()
|
|
54
58
|
|
|
55
59
|
resolve(null)
|
|
56
60
|
|
|
57
|
-
if (
|
|
58
|
-
yieldState = 1
|
|
61
|
+
if (shouldYield()) {
|
|
59
62
|
yieldSchedule(dispatchYield)
|
|
60
63
|
return
|
|
61
64
|
}
|
|
62
65
|
}
|
|
63
66
|
|
|
64
|
-
|
|
67
|
+
yieldScheduled = false
|
|
65
68
|
}
|