build: add packageManager field to package.json
[poolifier.git] / src / pools / cluster / dynamic.ts
index b93d7e87c4290a21b8a9b8f7c2845647d05592da..51d1cbeece56d374df9228cbee9dbdfed86f1989 100644 (file)
@@ -1,5 +1,6 @@
-import { type PoolType, PoolTypes } from '../pool'
-import { type ClusterPoolOptions, FixedClusterPool } from './fixed'
+import { PoolEvents, type PoolType, PoolTypes } from '../pool.js'
+import { checkDynamicPoolSize } from '../utils.js'
+import { type ClusterPoolOptions, FixedClusterPool } from './fixed.js'
 
 /**
  * A cluster pool with a dynamic number of workers, but a guaranteed minimum number of workers.
@@ -26,12 +27,27 @@ export class DynamicClusterPool<
    */
   public constructor (
     min: number,
-    protected readonly max: number,
+    max: number,
     filePath: string,
     opts: ClusterPoolOptions = {}
   ) {
-    super(min, filePath, opts)
-    this.checkDynamicPoolSize(this.numberOfWorkers, this.max)
+    super(min, filePath, opts, max)
+    checkDynamicPoolSize(
+      this.minimumNumberOfWorkers,
+      this.maximumNumberOfWorkers
+    )
+  }
+
+  /** @inheritDoc */
+  protected shallCreateDynamicWorker (): boolean {
+    return (!this.full && this.internalBusy()) || this.empty
+  }
+
+  /** @inheritDoc */
+  protected checkAndEmitDynamicWorkerCreationEvents (): void {
+    if (this.full) {
+      this.emitter?.emit(PoolEvents.full, this.info)
+    }
   }
 
   /** @inheritDoc */