@nxtedition/timers 1.1.0 → 1.1.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/README.md +1 -1
- package/lib/index.js +6 -5
- package/package.json +5 -3
- package/lib/index.bench.d.ts +0 -1
package/README.md
CHANGED
|
@@ -86,7 +86,7 @@ Cancel a pending timer. Works with both native and pooled handles. Passing `null
|
|
|
86
86
|
|
|
87
87
|
## How it works
|
|
88
88
|
|
|
89
|
-
All pooled timers share a single `setTimeout` handle that fires every 500ms. On each tick, pending timers are checked and expired ones are fired.
|
|
89
|
+
All pooled timers share a single `setTimeout` handle that fires every 500ms. On each tick, pending timers are checked and expired ones are fired. A +250ms offset is applied to each deadline to center the quantisation error, so pooled timers fire within ±250ms of the requested delay. This dramatically reduces the number of active OS timer handles when many long-lived timers are in use (e.g. connection idle timeouts, retry delays).
|
|
90
90
|
|
|
91
91
|
**Note:** Timers with the same delay are not guaranteed to fire in creation order. The execution order of same-delay timers is nondeterministic.
|
|
92
92
|
|
package/lib/index.js
CHANGED
|
@@ -12,9 +12,7 @@ function dispatch() {
|
|
|
12
12
|
while (fastIndex < len) {
|
|
13
13
|
const timer = fastTimers[fastIndex]
|
|
14
14
|
|
|
15
|
-
if (timer.state
|
|
16
|
-
timer.state = fastNow + timer.delay
|
|
17
|
-
} else if (timer.state > 0 && fastNow >= timer.state) {
|
|
15
|
+
if (timer.state > 0 && fastNow >= timer.state) {
|
|
18
16
|
timer.state = -1
|
|
19
17
|
timer.callback(timer.opaque)
|
|
20
18
|
}
|
|
@@ -64,7 +62,6 @@ class Timeout {
|
|
|
64
62
|
|
|
65
63
|
// -2 not in timer list
|
|
66
64
|
// -1 in timer list but inactive
|
|
67
|
-
// 0 in timer list waiting for time
|
|
68
65
|
// > 0 in timer list waiting for time to expire
|
|
69
66
|
state = -2
|
|
70
67
|
|
|
@@ -83,7 +80,11 @@ class Timeout {
|
|
|
83
80
|
}
|
|
84
81
|
}
|
|
85
82
|
|
|
86
|
-
|
|
83
|
+
// Offset by half the tick interval to center the timing error.
|
|
84
|
+
// fastNow only advances every 500ms so the actual fire time can
|
|
85
|
+
// deviate from the requested delay. Without this offset the error
|
|
86
|
+
// is up to -500ms (early); with it the worst case is ±250ms.
|
|
87
|
+
this.state = fastNow + this.delay + 250
|
|
87
88
|
}
|
|
88
89
|
|
|
89
90
|
clear() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxtedition/timers",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -22,7 +22,9 @@
|
|
|
22
22
|
"benchmark": "node --experimental-strip-types src/index.bench.ts"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
+
"@sinonjs/fake-timers": "^15.3.2",
|
|
25
26
|
"@types/node": "^25.5.0",
|
|
27
|
+
"@types/sinonjs__fake-timers": "^15.0.1",
|
|
26
28
|
"amaroc": "^1.0.1",
|
|
27
29
|
"mitata": "^1.0.34",
|
|
28
30
|
"oxlint-tsgolint": "^0.17.0",
|
|
@@ -30,7 +32,7 @@
|
|
|
30
32
|
"typescript": "^5.9.3"
|
|
31
33
|
},
|
|
32
34
|
"dependencies": {
|
|
33
|
-
"@nxtedition/yield": "^1.0.
|
|
35
|
+
"@nxtedition/yield": "^1.0.16"
|
|
34
36
|
},
|
|
35
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "a29e479679bd053fa37ff8868d47918a8983ee48"
|
|
36
38
|
}
|
package/lib/index.bench.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|