perf: avoid branching on pool type
[poolifier.git] / src / pools / cluster / dynamic.ts
index 9636b423915fc670c9b42f24680cee131f343c3a..08ebc75c76a66ba5ca311c2e269988d741ad5aff 100644 (file)
@@ -1,5 +1,5 @@
 import { checkDynamicPoolSize } from '../utils'
-import { type PoolType, PoolTypes } from '../pool'
+import { PoolEvents, type PoolType, PoolTypes } from '../pool'
 import { type ClusterPoolOptions, FixedClusterPool } from './fixed'
 
 /**
@@ -38,6 +38,18 @@ export class DynamicClusterPool<
     )
   }
 
+  /** @inheritDoc */
+  protected shallCreateDynamicWorker (): boolean {
+    return !this.full && this.internalBusy()
+  }
+
+  /** @inheritDoc */
+  protected checkAndEmitDynamicWorkerCreationEvents (): void {
+    if (this.full) {
+      this.emitter?.emit(PoolEvents.full, this.info)
+    }
+  }
+
   /** @inheritDoc */
   protected get type (): PoolType {
     return PoolTypes.dynamic