@nxtedition/lib 23.17.13 → 23.17.14
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/app.js +1 -1
- package/http.js +1 -1
- package/package.json +1 -1
- package/yield.js +88 -15
package/app.js
CHANGED
|
@@ -902,7 +902,7 @@ export function makeApp(appConfig, onTerminate) {
|
|
|
902
902
|
)
|
|
903
903
|
|
|
904
904
|
const loggerSubscription = status$
|
|
905
|
-
.pipe(rx.pluck('messages'), rx.startWith([]), rx.pairwise())
|
|
905
|
+
.pipe(rx.auditTime(1e3), rx.pluck('messages'), rx.startWith([]), rx.pairwise())
|
|
906
906
|
.subscribe(([prev, next]) => {
|
|
907
907
|
for (const { level, msg: status, ...message } of fp.differenceBy('id', next, prev)) {
|
|
908
908
|
if (level >= 50) {
|
package/http.js
CHANGED
package/package.json
CHANGED
package/yield.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { FixedQueue } from './fixed-queue.js'
|
|
2
|
+
import * as timers from './timers.js'
|
|
2
3
|
|
|
3
|
-
const
|
|
4
|
+
export const YIELD_PRIORITY_HIGH = 0
|
|
5
|
+
export const YIELD_PRIORITY_NORMAL = 1
|
|
6
|
+
export const YIELD_PRIORITY_LOW = 2
|
|
7
|
+
export const YIELD_PRIORITY_COUNT = 3
|
|
8
|
+
|
|
9
|
+
const yieldQueue = new Array(YIELD_PRIORITY_COUNT).fill(null).map(() => new FixedQueue())
|
|
4
10
|
const yieldSchedule = globalThis.setImmediate ?? ((fn) => setTimeout(fn, 0))
|
|
5
11
|
|
|
6
12
|
let yieldTimeout = 40
|
|
@@ -8,6 +14,8 @@ let yieldActive = false
|
|
|
8
14
|
let yieldScheduled = false
|
|
9
15
|
let yieldTime = performance.now()
|
|
10
16
|
|
|
17
|
+
const POOL = []
|
|
18
|
+
|
|
11
19
|
export function setYieldTimeout(timeout) {
|
|
12
20
|
if (typeof timeout !== 'number' || timeout < 0) {
|
|
13
21
|
throw new TypeError('timeout must be a positive number')
|
|
@@ -15,6 +23,26 @@ export function setYieldTimeout(timeout) {
|
|
|
15
23
|
yieldTimeout = timeout
|
|
16
24
|
}
|
|
17
25
|
|
|
26
|
+
export function setTimeout(callback, timeout, opaque, priority) {
|
|
27
|
+
if (typeof callback !== 'function') {
|
|
28
|
+
throw new TypeError('callback must be a function')
|
|
29
|
+
}
|
|
30
|
+
if (typeof timeout !== 'number' || timeout < 0) {
|
|
31
|
+
throw new TypeError('timeout must be a positive number')
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return timers.setTimeout((opaque) => maybeYield(callback, opaque, priority), timeout, opaque)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function clearTimeout(timeout) {
|
|
38
|
+
timers.clearTimeout(timeout)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// TODO (fix): Return a handle?
|
|
42
|
+
export function setImmediate(callback, opaque, priority) {
|
|
43
|
+
maybeYield(callback, opaque, priority)
|
|
44
|
+
}
|
|
45
|
+
|
|
18
46
|
export function shouldYield() {
|
|
19
47
|
if (!yieldActive && performance.now() - yieldTime >= yieldTimeout) {
|
|
20
48
|
yieldActive = true
|
|
@@ -22,54 +50,99 @@ export function shouldYield() {
|
|
|
22
50
|
return yieldActive
|
|
23
51
|
}
|
|
24
52
|
|
|
25
|
-
export function maybeYield(callback) {
|
|
53
|
+
export function maybeYield(callback, opaque, priority) {
|
|
26
54
|
if (callback != null && typeof callback !== 'function') {
|
|
27
55
|
throw new TypeError('callback must be a function')
|
|
28
56
|
}
|
|
29
57
|
|
|
30
58
|
if (shouldYield()) {
|
|
31
|
-
return doYield(callback)
|
|
59
|
+
return doYield(callback, opaque, priority)
|
|
32
60
|
}
|
|
33
61
|
|
|
34
62
|
if (callback != null) {
|
|
35
|
-
callback(
|
|
63
|
+
callback(opaque)
|
|
36
64
|
}
|
|
37
65
|
|
|
38
66
|
return null
|
|
39
67
|
}
|
|
40
68
|
|
|
41
|
-
export function doYield(callback) {
|
|
69
|
+
export function doYield(callback, opaque, priority) {
|
|
42
70
|
if (callback != null && typeof callback !== 'function') {
|
|
43
71
|
throw new TypeError('callback must be a function')
|
|
44
72
|
}
|
|
45
73
|
|
|
74
|
+
if (priority === undefined) {
|
|
75
|
+
priority = YIELD_PRIORITY_NORMAL
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (priority < 0 || priority >= YIELD_PRIORITY_COUNT) {
|
|
79
|
+
throw new RangeError('invalid priority')
|
|
80
|
+
}
|
|
81
|
+
|
|
46
82
|
if (!yieldScheduled) {
|
|
47
83
|
yieldScheduled = true
|
|
48
84
|
yieldSchedule(dispatchYield)
|
|
49
85
|
}
|
|
50
86
|
|
|
51
87
|
if (callback != null) {
|
|
52
|
-
|
|
88
|
+
if (opaque !== undefined) {
|
|
89
|
+
const arr = POOL.pop() ?? [null, null]
|
|
90
|
+
arr[0] = callback
|
|
91
|
+
arr[1] = opaque
|
|
92
|
+
yieldQueue[priority].push(arr)
|
|
93
|
+
} else {
|
|
94
|
+
yieldQueue[priority].push(callback)
|
|
95
|
+
}
|
|
53
96
|
return null
|
|
54
97
|
}
|
|
55
98
|
|
|
56
99
|
return new Promise((resolve) => {
|
|
57
|
-
|
|
100
|
+
if (opaque !== undefined) {
|
|
101
|
+
const arr = POOL.pop() ?? [null, null]
|
|
102
|
+
arr[0] = resolve
|
|
103
|
+
arr[1] = opaque
|
|
104
|
+
yieldQueue[priority].push(arr)
|
|
105
|
+
} else {
|
|
106
|
+
yieldQueue[priority].push(callback)
|
|
107
|
+
}
|
|
58
108
|
})
|
|
59
109
|
}
|
|
60
110
|
|
|
111
|
+
function dispatchItem(item) {
|
|
112
|
+
if (item == null) {
|
|
113
|
+
return
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
let callback
|
|
117
|
+
let opaque = null
|
|
118
|
+
|
|
119
|
+
if (Array.isArray(item)) {
|
|
120
|
+
callback = item[0]
|
|
121
|
+
opaque = item[1]
|
|
122
|
+
if (POOL.length < 4096) {
|
|
123
|
+
item[0] = null
|
|
124
|
+
item[1] = null
|
|
125
|
+
POOL.push(item)
|
|
126
|
+
}
|
|
127
|
+
} else {
|
|
128
|
+
callback = item
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
callback(opaque)
|
|
132
|
+
}
|
|
133
|
+
|
|
61
134
|
function dispatchYield() {
|
|
62
135
|
yieldTime = performance.now()
|
|
63
136
|
yieldActive = false
|
|
64
137
|
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
138
|
+
for (let i = 0; i < YIELD_PRIORITY_COUNT; i++) {
|
|
139
|
+
const queue = yieldQueue[i]
|
|
140
|
+
while (!queue.isEmpty()) {
|
|
141
|
+
if (shouldYield()) {
|
|
142
|
+
yieldSchedule(dispatchYield)
|
|
143
|
+
return
|
|
144
|
+
}
|
|
145
|
+
dispatchItem(queue.shift())
|
|
73
146
|
}
|
|
74
147
|
}
|
|
75
148
|
|