@nxtedition/lib 23.17.0 → 23.17.1

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 (2) hide show
  1. package/package.json +1 -1
  2. package/yield.js +12 -37
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "23.17.0",
3
+ "version": "23.17.1",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",
package/yield.js CHANGED
@@ -1,12 +1,6 @@
1
1
  import { FixedQueue } from './fixed-queue.js'
2
2
 
3
- const yieldQueues = [new FixedQueue(), new FixedQueue(), new FixedQueue()]
4
- const yieldQueueLength = yieldQueues.length
5
-
6
- export const PRIORITY_HIGH = 0
7
- export const PRIORITY_NORMAL = 1
8
- export const PRIORITY_LOW = 2
9
-
3
+ const yieldQueue = new FixedQueue()
10
4
  const yieldSchedule = globalThis.setImmediate ?? ((fn) => setTimeout(fn, 0))
11
5
 
12
6
  let yieldTimeout = 40
@@ -28,13 +22,13 @@ export function shouldYield() {
28
22
  return yieldActive
29
23
  }
30
24
 
31
- export function maybeYield(callback, priority) {
25
+ export function maybeYield(callback) {
32
26
  if (callback != null && typeof callback !== 'function') {
33
27
  throw new TypeError('callback must be a function')
34
28
  }
35
29
 
36
30
  if (shouldYield()) {
37
- return doYield(callback, priority)
31
+ return doYield(callback)
38
32
  }
39
33
 
40
34
  if (callback != null) {
@@ -44,39 +38,23 @@ export function maybeYield(callback, priority) {
44
38
  return null
45
39
  }
46
40
 
47
- export function doYield(callbackOrPriority, priorityOrNil) {
48
- let callback = callbackOrPriority
49
- let priority = priorityOrNil
50
-
51
- if (callbackOrPriority == null) {
52
- // Do nothing...
53
- } else if (typeof callbackOrPriority === 'number' && priorityOrNil == null) {
54
- priority = callbackOrPriority
55
- callback = null
56
- } else {
57
- callback = callbackOrPriority
58
- }
59
-
41
+ export function doYield(callback) {
60
42
  if (callback != null && typeof callback !== 'function') {
61
43
  throw new TypeError('callback must be a function')
62
44
  }
63
45
 
64
- if (priority != null && typeof priority !== 'number') {
65
- throw new TypeError('priority must be a number')
66
- }
67
-
68
46
  if (!yieldScheduled) {
69
47
  yieldScheduled = true
70
48
  yieldSchedule(dispatchYield)
71
49
  }
72
50
 
73
51
  if (callback != null) {
74
- yieldQueues[priority ?? PRIORITY_NORMAL].push(callback)
52
+ yieldQueue.push(callback)
75
53
  return null
76
54
  }
77
55
 
78
56
  return new Promise((resolve) => {
79
- yieldQueues[priority ?? PRIORITY_NORMAL].push(resolve)
57
+ yieldQueue.push(resolve)
80
58
  })
81
59
  }
82
60
 
@@ -84,17 +62,14 @@ function dispatchYield() {
84
62
  yieldTime = performance.now()
85
63
  yieldActive = false
86
64
 
87
- for (let n = 0; n < yieldQueueLength; n++) {
88
- const yieldQueue = yieldQueues[n]
89
- while (!yieldQueue.isEmpty()) {
90
- const resolve = yieldQueue.shift()
65
+ while (!yieldQueue.isEmpty()) {
66
+ const resolve = yieldQueue.shift()
91
67
 
92
- resolve(null)
68
+ resolve(null)
93
69
 
94
- if (shouldYield()) {
95
- yieldSchedule(dispatchYield)
96
- return
97
- }
70
+ if (shouldYield()) {
71
+ yieldSchedule(dispatchYield)
72
+ return
98
73
  }
99
74
  }
100
75