@nxtedition/lib 23.17.17 → 23.17.19

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.
Files changed (3) hide show
  1. package/app.js +1 -2
  2. package/package.json +1 -1
  3. package/yield.js +26 -17
package/app.js CHANGED
@@ -38,7 +38,6 @@ import { isTimeBetween } from './time.js'
38
38
  import makeUnderPressure from './under-pressure.js'
39
39
  import undici from '@nxtedition/undici'
40
40
  import { isPrimary } from 'node:cluster'
41
- import { doYield } from './yield.js'
42
41
 
43
42
  export function makeApp(appConfig, onTerminate) {
44
43
  let ds
@@ -398,7 +397,7 @@ export function makeApp(appConfig, onTerminate) {
398
397
  {
399
398
  userAgent,
400
399
  url: isProduction ? 'ws://deepstream:6020/deepstream' : 'ws://127.0.0.1:6020/deepstream',
401
- schedule: (fn) => doYield(fn),
400
+ schedule: (fn) => setImmediate(fn),
402
401
  },
403
402
  appConfig.deepstream,
404
403
  config.deepstream,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "23.17.17",
3
+ "version": "23.17.19",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",
package/yield.js CHANGED
@@ -1,8 +1,7 @@
1
- import { FixedQueue } from './fixed-queue.js'
2
-
3
1
  const yieldSchedule = globalThis.setImmediate ?? ((fn) => setTimeout(fn, 0))
2
+ const yieldQueue = []
4
3
 
5
- let yieldQueue = new FixedQueue()
4
+ let yieldIndex = 0
6
5
  let yieldTimeout = 40
7
6
  let yieldActive = false
8
7
  let yieldScheduled = false
@@ -22,23 +21,23 @@ export function shouldYield() {
22
21
  return yieldActive
23
22
  }
24
23
 
25
- export function maybeYield(callback) {
24
+ export function maybeYield(callback, opaque) {
26
25
  if (callback != null && typeof callback !== 'function') {
27
26
  throw new TypeError('callback must be a function')
28
27
  }
29
28
 
30
29
  if (shouldYield()) {
31
- return doYield(callback)
30
+ return doYield(callback, opaque)
32
31
  }
33
32
 
34
33
  if (callback != null) {
35
- callback(null)
34
+ callback(null, opaque)
36
35
  }
37
36
 
38
37
  return null
39
38
  }
40
39
 
41
- export function doYield(callback) {
40
+ export function doYield(callback, opaque) {
42
41
  if (callback != null && typeof callback !== 'function') {
43
42
  throw new TypeError('callback must be a function')
44
43
  }
@@ -49,12 +48,12 @@ export function doYield(callback) {
49
48
  }
50
49
 
51
50
  if (callback != null) {
52
- yieldQueue.push(callback)
51
+ yieldQueue.push(callback, opaque)
53
52
  return null
54
53
  }
55
54
 
56
55
  return new Promise((resolve) => {
57
- yieldQueue.push(resolve)
56
+ yieldQueue.push(resolve, opaque)
58
57
  })
59
58
  }
60
59
 
@@ -62,23 +61,33 @@ function dispatchYield() {
62
61
  yieldTime = performance.now()
63
62
  yieldActive = false
64
63
 
65
- const queue = yieldQueue
66
- yieldQueue = new FixedQueue()
64
+ const maxIndex = yieldQueue.length
65
+
66
+ while (yieldIndex < maxIndex) {
67
+ const resolve = yieldQueue[yieldIndex]
68
+ yieldQueue[yieldIndex] = null
69
+ yieldIndex += 1
67
70
 
68
- while (!queue.isEmpty()) {
69
- const resolve = queue.shift()
71
+ const opaque = yieldQueue[yieldIndex]
72
+ yieldQueue[yieldIndex] = null
73
+ yieldIndex += 1
70
74
 
71
- resolve(null)
75
+ resolve(opaque)
72
76
 
73
77
  if (shouldYield()) {
74
- yieldSchedule(dispatchYield)
75
- return
78
+ break
76
79
  }
77
80
  }
78
81
 
79
- if (yieldQueue.isEmpty()) {
82
+ if (yieldIndex === yieldQueue.length) {
80
83
  yieldScheduled = false
84
+ yieldQueue.splice(0)
85
+ yieldIndex = 0
81
86
  } else {
87
+ if (yieldIndex > 16 * 1024) {
88
+ yieldQueue.splice(0, yieldIndex)
89
+ yieldIndex = 0
90
+ }
82
91
  yieldSchedule(dispatchYield)
83
92
  }
84
93
  }