X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fcluster%2Fdynamic.ts;h=51d1cbeece56d374df9228cbee9dbdfed86f1989;hb=ecde6ea8c439bbdd9dc2ca118731b5006a1a9884;hp=b93d7e87c4290a21b8a9b8f7c2845647d05592da;hpb=0676e5d32c8f8ee5c5b7f5998f4973b0a276460f;p=poolifier.git diff --git a/src/pools/cluster/dynamic.ts b/src/pools/cluster/dynamic.ts index b93d7e87..51d1cbee 100644 --- a/src/pools/cluster/dynamic.ts +++ b/src/pools/cluster/dynamic.ts @@ -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 */