fix: fix fair share worker choice strategy internals update
[poolifier.git] / src / pools / selection-strategies / worker-choice-strategy-context.ts
index 2b3c9fb68b33b1d4925f9dab7be3cf14b123bf88..124addd64f113cf5e4ffe7dac66b902ff86faedf 100644 (file)
@@ -131,13 +131,18 @@ export class WorkerChoiceStrategyContext<
    * Executes the worker choice strategy algorithm in the context.
    *
    * @returns The key of the worker node.
+   * @throws {@link Error} If the worker node key is null or undefined.
    */
   public execute (): number {
-    return (
+    const workerNodeKey = (
       this.workerChoiceStrategies.get(
         this.workerChoiceStrategy
       ) as IWorkerChoiceStrategy
     ).choose()
+    if (workerNodeKey == null) {
+      throw new Error('Worker node key chosen is null or undefined')
+    }
+    return workerNodeKey
   }
 
   /**