Merge branch 'master' of github.com:jerome-benoit/poolifier
[poolifier.git] / src / pools / abstract-pool.ts
index 03f8c199be642dda1cac20171d0b2410ef73d1c3..283b04d682b4a656b6a430a78714a9ae52582e72 100644 (file)
@@ -1,6 +1,5 @@
 import crypto from 'node:crypto'
 import { performance } from 'node:perf_hooks'
-import { readFileSync } from 'node:fs'
 import type { MessageValue, PromiseResponseWrapper } from '../utility-types'
 import {
   DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS,
@@ -39,12 +38,7 @@ import {
   type WorkerChoiceStrategyOptions
 } from './selection-strategies/selection-strategies-types'
 import { WorkerChoiceStrategyContext } from './selection-strategies/worker-choice-strategy-context'
-
-const version = (
-  JSON.parse(
-    readFileSync(new URL('../../package.json', import.meta.url), 'utf8')
-  ) as Record<string, unknown>
-).version as string
+import { version } from './version'
 
 /**
  * Base class that implements some shared logic for all poolifier pools.
@@ -306,22 +300,14 @@ export abstract class AbstractPool<
     }
   }
 
-  /**
-   * Gets the pool run time.
-   *
-   * @returns The pool run time in milliseconds.
-   */
-  private get runTime (): number {
-    return performance.now() - this.startTimestamp
-  }
-
   /**
    * Gets the approximate pool utilization.
    *
    * @returns The pool utilization.
    */
   private get utilization (): number {
-    const poolRunTimeCapacity = this.runTime * this.maxSize
+    const poolRunTimeCapacity =
+      (performance.now() - this.startTimestamp) * this.maxSize
     const totalTasksRunTime = this.workerNodes.reduce(
       (accumulator, workerNode) =>
         accumulator + workerNode.usage.runTime.aggregate,