fix: ensure worker node is defined before emitting
[poolifier.git] / src / pools / cluster / dynamic.ts
index 311d5c9d9393157205d03e5029f5515d7ba9a46b..7b2c37984ece0bff91021777653d90e6c3e5ccab 100644 (file)
@@ -34,13 +34,16 @@ export class DynamicClusterPool<
     super(min, filePath, opts, max)
     checkDynamicPoolSize(
       this.minimumNumberOfWorkers,
-      this.maximumNumberOfWorkers as number
+      this.maximumNumberOfWorkers
     )
   }
 
   /** @inheritDoc */
   protected shallCreateDynamicWorker (): boolean {
-    return !this.full && this.internalBusy()
+    return (
+      (!this.full && this.internalBusy()) ||
+      (this.minimumNumberOfWorkers === 0 && this.workerNodes.length === 0)
+    )
   }
 
   /** @inheritDoc */