X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fcluster%2Fdynamic.ts;h=8ef11c00d8975f38cded441e0ac4a42a639e9116;hb=ce63d9e2f3d895bd2ae5aafc40769ff4dda3c887;hp=99a89966e914507fa6868883a0f67c751c8b29c6;hpb=bde6b5d701d895c3e1b447f48750d42a7ac66603;p=poolifier.git diff --git a/src/pools/cluster/dynamic.ts b/src/pools/cluster/dynamic.ts index 99a89966..8ef11c00 100644 --- a/src/pools/cluster/dynamic.ts +++ b/src/pools/cluster/dynamic.ts @@ -1,6 +1,6 @@ -import { type PoolType, PoolTypes } from '../pool' -import { checkDynamicPoolSize } from '../utils' -import { type ClusterPoolOptions, FixedClusterPool } from './fixed' +import { checkDynamicPoolSize } from '../utils.js' +import { PoolEvents, type PoolType, PoolTypes } from '../pool.js' +import { type ClusterPoolOptions, FixedClusterPool } from './fixed.js' /** * A cluster pool with a dynamic number of workers, but a guaranteed minimum number of workers. @@ -27,12 +27,28 @@ export class DynamicClusterPool< */ public constructor ( min: number, - protected readonly max: number, + max: number, filePath: string, opts: ClusterPoolOptions = {} ) { - super(min, filePath, opts) - checkDynamicPoolSize(this.numberOfWorkers, this.max) + super(min, filePath, opts, max) + checkDynamicPoolSize( + this.minimumNumberOfWorkers, + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + this.maximumNumberOfWorkers! + ) + } + + /** @inheritDoc */ + protected shallCreateDynamicWorker (): boolean { + return !this.full && this.internalBusy() + } + + /** @inheritDoc */ + protected checkAndEmitDynamicWorkerCreationEvents (): void { + if (this.full) { + this.emitter?.emit(PoolEvents.full, this.info) + } } /** @inheritDoc */