X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fpools%2Fcluster%2Fdynamic.ts;h=51d1cbeece56d374df9228cbee9dbdfed86f1989;hb=aff95fe77c1dd978bd393d823b83267970ef6a70;hp=9636b423915fc670c9b42f24680cee131f343c3a;hpb=2889bd70182e9e42c75d686ece3c288307e01d4f;p=poolifier.git diff --git a/src/pools/cluster/dynamic.ts b/src/pools/cluster/dynamic.ts index 9636b423..51d1cbee 100644 --- a/src/pools/cluster/dynamic.ts +++ b/src/pools/cluster/dynamic.ts @@ -1,6 +1,6 @@ -import { checkDynamicPoolSize } from '../utils' -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. @@ -34,10 +34,22 @@ 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()) || this.empty + } + + /** @inheritDoc */ + protected checkAndEmitDynamicWorkerCreationEvents (): void { + if (this.full) { + this.emitter?.emit(PoolEvents.full, this.info) + } + } + /** @inheritDoc */ protected get type (): PoolType { return PoolTypes.dynamic