fix: fix default worker data value
[poolifier.git] / src / pools / selection-strategies / dynamic-pool-worker-choice-strategy.ts
index 9b4b6ddeeaa2c520ef2252c9e47ac0b061f5a4fa..5f07d60794b07e9c4eb9846f4d9ea9d1847a1caa 100644 (file)
@@ -6,28 +6,28 @@ import type {
   WorkerChoiceStrategy
 } from './selection-strategies-types'
 import { WorkerChoiceStrategies } from './selection-strategies-types'
-import { SelectionStrategiesUtils } from './selection-strategies-utils'
+import { getWorkerChoiceStrategy } from './selection-strategies-utils'
 
 /**
  * Selects the next worker for dynamic pool.
  *
- * @template Worker Type of worker which manages the strategy.
- * @template Data Type of data sent to the worker. This can only be serializable data.
- * @template Response Type of response of execution. This can only be serializable data.
+ * @typeParam Worker - Type of worker which manages the strategy.
+ * @typeParam Data - Type of data sent to the worker. This can only be serializable data.
+ * @typeParam Response - Type of response of execution. This can only be serializable data.
  */
 export class DynamicPoolWorkerChoiceStrategy<
   Worker extends IPoolWorker,
   Data,
   Response
 > extends AbstractWorkerChoiceStrategy<Worker, Data, Response> {
-  private workerChoiceStrategy: IWorkerChoiceStrategy<Worker>
+  private readonly workerChoiceStrategy: IWorkerChoiceStrategy<Worker>
 
   /**
    * Constructs a worker choice strategy for dynamic pool.
    *
-   * @param pool The pool instance.
-   * @param createDynamicallyWorkerCallback The worker creation callback for dynamic pool.
-   * @param workerChoiceStrategy The worker choice strategy when the pull is busy.
+   * @param pool The pool instance.
+   * @param createDynamicallyWorkerCallback The worker creation callback for dynamic pool.
+   * @param workerChoiceStrategy The worker choice strategy when the pull is busy.
    */
   public constructor (
     pool: IPoolInternal<Worker, Data, Response>,
@@ -35,26 +35,26 @@ export class DynamicPoolWorkerChoiceStrategy<
     workerChoiceStrategy: WorkerChoiceStrategy = WorkerChoiceStrategies.ROUND_ROBIN
   ) {
     super(pool)
-    this.workerChoiceStrategy = SelectionStrategiesUtils.getWorkerChoiceStrategy(
+    this.workerChoiceStrategy = getWorkerChoiceStrategy(
       this.pool,
       workerChoiceStrategy
     )
     this.requiredStatistics = this.workerChoiceStrategy.requiredStatistics
   }
 
-  /** @inheritDoc */
+  /** {@inheritDoc} */
   public reset (): boolean {
     return this.workerChoiceStrategy.reset()
   }
 
-  /** @inheritDoc */
+  /** {@inheritDoc} */
   public choose (): Worker {
     const freeWorker = this.pool.findFreeWorker()
-    if (freeWorker) {
+    if (freeWorker !== false) {
       return freeWorker
     }
 
-    if (this.pool.busy === true) {
+    if (this.pool.busy) {
       return this.workerChoiceStrategy.choose()
     }