X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fthread%2Fdynamic.ts;h=836cae0b0615e1f74733e09f9f21b450bf15506b;hb=61ee03c80d4de04751bf0218d9574bbd8c94e159;hp=a34f0c25f78b1da3a306c9c07edb5c5d43f0f21b;hpb=a25c335d7e5573a171fc96c445cb6092852b2c4a;p=poolifier.git diff --git a/src/pools/thread/dynamic.ts b/src/pools/thread/dynamic.ts index a34f0c25..836cae0b 100644 --- a/src/pools/thread/dynamic.ts +++ b/src/pools/thread/dynamic.ts @@ -1,5 +1,6 @@ -import { type PoolType, PoolTypes } from '../pool' -import { FixedThreadPool, type ThreadPoolOptions } from './fixed' +import { PoolEvents, type PoolType, PoolTypes } from '../pool.js' +import { checkDynamicPoolSize } from '../utils.js' +import { FixedThreadPool, type ThreadPoolOptions } from './fixed.js' /** * A thread pool with a dynamic number of threads, but a guaranteed minimum number of threads. @@ -26,12 +27,31 @@ export class DynamicThreadPool< */ public constructor ( min: number, - protected readonly max: number, + max: number, filePath: string, opts: ThreadPoolOptions = {} ) { - super(min, filePath, opts) - this.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()) || + (this.minimumNumberOfWorkers === 0 && this.workerNodes.length === 0) + ) + } + + /** @inheritDoc */ + protected checkAndEmitDynamicWorkerCreationEvents (): void { + if (this.full) { + this.emitter?.emit(PoolEvents.full, this.info) + } } /** @inheritDoc */