@nxtedition/timers 1.0.1 → 1.0.3
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 +20 -8
- package/package.json +7 -4
package/lib/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
import { doYield, shouldYield } from '@nxtedition/yield'
|
|
2
|
+
|
|
1
3
|
let fastNow = 0
|
|
2
4
|
let fastNowTimeout = null
|
|
5
|
+
let fastIndex = 0
|
|
3
6
|
|
|
4
7
|
const fastTimers = []
|
|
5
8
|
|
|
6
|
-
function
|
|
7
|
-
fastNow += 500
|
|
8
|
-
|
|
9
|
+
function dispatch() {
|
|
9
10
|
let len = fastTimers.length
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const timer = fastTimers[idx]
|
|
11
|
+
while (fastIndex < len) {
|
|
12
|
+
const timer = fastTimers[fastIndex]
|
|
13
13
|
|
|
14
14
|
if (timer.state === 0) {
|
|
15
15
|
timer.state = fastNow + timer.delay
|
|
@@ -22,19 +22,31 @@ function onTimeout() {
|
|
|
22
22
|
timer.state = -2
|
|
23
23
|
const tmp = fastTimers.pop()
|
|
24
24
|
if (tmp !== timer) {
|
|
25
|
-
fastTimers[
|
|
25
|
+
fastTimers[fastIndex] = tmp
|
|
26
26
|
}
|
|
27
27
|
len -= 1
|
|
28
28
|
} else {
|
|
29
|
-
|
|
29
|
+
fastIndex += 1
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if ((fastIndex & 0xff) === 0 && shouldYield()) {
|
|
33
|
+
doYield(dispatch)
|
|
34
|
+
return
|
|
30
35
|
}
|
|
31
36
|
}
|
|
32
37
|
|
|
38
|
+
fastIndex = 0
|
|
39
|
+
|
|
33
40
|
if (fastTimers.length > 0) {
|
|
34
41
|
refreshTimeout()
|
|
35
42
|
}
|
|
36
43
|
}
|
|
37
44
|
|
|
45
|
+
function onTimeout() {
|
|
46
|
+
fastNow += 500
|
|
47
|
+
dispatch()
|
|
48
|
+
}
|
|
49
|
+
|
|
38
50
|
function refreshTimeout() {
|
|
39
51
|
if (fastNowTimeout) {
|
|
40
52
|
fastNowTimeout.refresh()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxtedition/timers",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -25,9 +25,12 @@
|
|
|
25
25
|
"@types/node": "^25.2.3",
|
|
26
26
|
"amaroc": "^1.0.1",
|
|
27
27
|
"mitata": "^1.0.34",
|
|
28
|
-
"oxlint-tsgolint": "^0.
|
|
29
|
-
"rimraf": "^6.1.
|
|
28
|
+
"oxlint-tsgolint": "^0.13.0",
|
|
29
|
+
"rimraf": "^6.1.3",
|
|
30
30
|
"typescript": "^5.9.3"
|
|
31
31
|
},
|
|
32
|
-
"
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@nxtedition/yield": "^1.0.11"
|
|
34
|
+
},
|
|
35
|
+
"gitHead": "05f9f940c3b262e4c5431c953ac93bc159ade0a0"
|
|
33
36
|
}
|