chore: generate documentation
[poolifier.git] / src / utils.ts
index 164a2aca5eeeec3ae86b9bfcdeeb72d872c32cb7..a6f5fbcc5b729b98f5dec1da1de8178eff830d40 100644 (file)
@@ -1,4 +1,8 @@
-import type { WorkerChoiceStrategyOptions } from './pools/selection-strategies/selection-strategies-types'
+import os from 'node:os'
+import type {
+  MeasurementStatisticsRequirements,
+  WorkerChoiceStrategyOptions
+} from './pools/selection-strategies/selection-strategies-types'
 
 /**
  * An intentional empty function.
@@ -12,9 +16,37 @@ export const EMPTY_FUNCTION: () => void = Object.freeze(() => {
  */
 export const DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS: WorkerChoiceStrategyOptions =
   {
-    medRunTime: false
+    runTime: { median: false },
+    waitTime: { median: false },
+    elu: { median: false }
   }
 
+/**
+ * Default measurement statistics requirements.
+ */
+export const DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS: MeasurementStatisticsRequirements =
+  {
+    aggregate: false,
+    average: false,
+    median: false
+  }
+
+/**
+ * Safe helper to get the host OS optimized maximum pool size.
+ */
+export const availableParallelism = (): number => {
+  let availableParallelism = 1
+  try {
+    availableParallelism = os.availableParallelism()
+  } catch {
+    const cpus = os.cpus()
+    if (Array.isArray(cpus) && cpus.length > 0) {
+      availableParallelism = cpus.length
+    }
+  }
+  return availableParallelism
+}
+
 /**
  * Compute the median of the given data set.
  *