fix: ensure worker removal impact is propated to worker choice strategy
[poolifier.git] / src / pools / selection-strategies / worker-choice-strategy-context.ts
index c149cc2e9b48a7a6dae62466aea312fd9054e6dc..011e00db2060b08dffa193b28be907b35b2eb64c 100644 (file)
@@ -4,6 +4,7 @@ import type { IPoolWorker } from '../pool-worker'
 import { DynamicPoolWorkerChoiceStrategy } from './dynamic-pool-worker-choice-strategy'
 import type {
   IWorkerChoiceStrategy,
+  RequiredStatistics,
   WorkerChoiceStrategy
 } from './selection-strategies-types'
 import { WorkerChoiceStrategies } from './selection-strategies-types'
@@ -61,11 +62,21 @@ export class WorkerChoiceStrategyContext<
    * Gets the worker choice strategy used in the context.
    *
    * @returns The worker choice strategy.
+   * @deprecated Scheduled removal.
    */
   public getWorkerChoiceStrategy (): IWorkerChoiceStrategy {
     return this.workerChoiceStrategy
   }
 
+  /**
+   * Gets the worker choice strategy required statistics.
+   *
+   * @returns The required statistics.
+   */
+  public getRequiredStatistics (): RequiredStatistics {
+    return this.workerChoiceStrategy.requiredStatistics
+  }
+
   /**
    * Sets the worker choice strategy to use in the context.
    *
@@ -87,4 +98,14 @@ export class WorkerChoiceStrategyContext<
   public execute (): number {
     return this.workerChoiceStrategy.choose()
   }
+
+  /**
+   * Removes a worker in the underlying selection strategy internals.
+   *
+   * @param workerKey - The key of the worker to remove.
+   * @returns `true` if the removal is successful, `false` otherwise.
+   */
+  public remove (workerKey: number): boolean {
+    return this.workerChoiceStrategy.remove(workerKey)
+  }
 }