refactor: cleanup pool startup code
authorJérôme Benoit <jerome.benoit@sap.com>
Thu, 13 Jul 2023 18:19:09 +0000 (20:19 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Thu, 13 Jul 2023 18:19:09 +0000 (20:19 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/pools/abstract-pool.ts

index 7d3be8d693987f80cd4a5a5c7050334ac6e304d8..87427ad719079d1b4462661bcba473f94786127e 100644 (file)
@@ -133,15 +133,7 @@ export abstract class AbstractPool<
     this.setupHook()
 
     this.starting = true
-    while (
-      this.workerNodes.reduce(
-        (accumulator, workerNode) =>
-          !workerNode.info.dynamic ? accumulator + 1 : accumulator,
-        0
-      ) < this.numberOfWorkers
-    ) {
-      this.createAndSetupWorker()
-    }
+    this.startPool()
     this.starting = false
 
     this.startTimestamp = performance.now()
@@ -285,6 +277,18 @@ export abstract class AbstractPool<
     }
   }
 
+  private startPool (): void {
+    while (
+      this.workerNodes.reduce(
+        (accumulator, workerNode) =>
+          !workerNode.info.dynamic ? accumulator + 1 : accumulator,
+        0
+      ) < this.numberOfWorkers
+    ) {
+      this.createAndSetupWorker()
+    }
+  }
+
   /** @inheritDoc */
   public get info (): PoolInfo {
     return {