@nxtedition/lib 23.9.11 → 23.9.12

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/under-pressure.js +11 -17
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "23.9.11",
3
+ "version": "23.9.12",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",
package/under-pressure.js CHANGED
@@ -21,34 +21,28 @@ export default function (opts = {}) {
21
21
  let heapUsedBytes = 0
22
22
  let rssBytes = 0
23
23
  let eventLoopDelay = 0
24
- let elu
25
24
  let eventLoopUtilized = 0
26
25
 
27
- const histogram = monitorEventLoopDelay({ resolution })
28
- histogram.enable()
29
-
30
- if (performance.eventLoopUtilization) {
31
- elu = performance.eventLoopUtilization()
32
- }
33
-
34
26
  if (!maxEventLoopDelay && !maxHeapUsedBytes && !maxRssBytes && !maxEventLoopUtilization) {
35
27
  return
36
28
  }
37
29
 
30
+ const histogram = maxEventLoopDelay ? monitorEventLoopDelay({ resolution }) : null
31
+ histogram?.enable()
32
+ const elu = maxEventLoopUtilization ? performance.eventLoopUtilization?.() : null
33
+
38
34
  function updateEventLoopDelay() {
39
- eventLoopDelay = Math.max(0, histogram.mean / 1e6 - resolution)
40
- if (Number.isNaN(eventLoopDelay)) {
41
- eventLoopDelay = Infinity
35
+ if (histogram) {
36
+ eventLoopDelay = Math.max(0, histogram.mean / 1e6 - resolution)
37
+ if (Number.isNaN(eventLoopDelay)) {
38
+ eventLoopDelay = Infinity
39
+ }
40
+ histogram.reset()
42
41
  }
43
- histogram.reset()
44
42
  }
45
43
 
46
44
  function updateEventLoopUtilization() {
47
- if (elu) {
48
- eventLoopUtilized = performance.eventLoopUtilization(elu).utilization
49
- } else {
50
- eventLoopUtilized = 0
51
- }
45
+ eventLoopUtilized = elu ? performance.eventLoopUtilization(elu).utilization : 0
52
46
  }
53
47
 
54
48
  const timer = setTimeout(update, sampleInterval).unref()