fix: fix worker usage statistics handling
[poolifier.git] / src / utils.ts
index 54d0d8d6d3c20b822f7138229a3e31d583f7ce3e..82c38c09e7161fd06e2c6f1628fdaad1e8f4c63f 100644 (file)
@@ -257,38 +257,18 @@ export const updateMeasurementStatistics = (
       measurementStatistics.history.push(measurementValue)
       if (measurementRequirements.average) {
         measurementStatistics.average = average(measurementStatistics.history)
+      } else if (measurementStatistics.average != null) {
+        delete measurementStatistics.average
       }
       if (measurementRequirements.median) {
         measurementStatistics.median = median(measurementStatistics.history)
+      } else if (measurementStatistics.median != null) {
+        delete measurementStatistics.median
       }
     }
   }
 }
 
-/**
- * Executes a function once at a time.
- *
- * @param fn - The function to execute.
- * @param context - The context to bind the function to.
- * @returns The function to execute.
- */
-export const once = (
-  // eslint-disable-next-line @typescript-eslint/no-explicit-any
-  fn: (...args: any[]) => void,
-  context: unknown
-  // eslint-disable-next-line @typescript-eslint/no-explicit-any
-): ((...args: any[]) => void) => {
-  let called = false
-  // eslint-disable-next-line @typescript-eslint/no-explicit-any
-  return function (...args: any[]): void {
-    if (!called) {
-      called = true
-      fn.apply(context, args)
-      called = false
-    }
-  }
-}
-
 /**
  * Generate a cryptographically secure random number in the [0,1[ range
  *