X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fthread%2Fdynamic.ts;h=8e795512694aa41a2ea82b9c727e3ebd348b01c9;hb=9ef62ae7a28438954d80d0a1ffb23cee05dfbe2d;hp=b03ca47e27ab272233338e8e4fb751bb8de0d0e4;hpb=e102732c0e3966b81834b2c0bdd087eb051162ad;p=poolifier.git diff --git a/src/pools/thread/dynamic.ts b/src/pools/thread/dynamic.ts index b03ca47e..8e795512 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,21 +27,32 @@ export class DynamicThreadPool< */ public constructor ( min: number, - protected readonly max: number, + max: number, filePath: string, opts: ThreadPoolOptions = {} ) { - super(min, filePath, opts) + super(min, filePath, opts, max) + checkDynamicPoolSize( + this.minimumNumberOfWorkers, + this.maximumNumberOfWorkers + ) } /** @inheritDoc */ - protected get type (): PoolType { - return PoolTypes.dynamic + protected shallCreateDynamicWorker (): boolean { + return (!this.full && this.internalBusy()) || this.empty } /** @inheritDoc */ - protected get maxSize (): number { - return this.max + protected checkAndEmitDynamicWorkerCreationEvents (): void { + if (this.full) { + this.emitter?.emit(PoolEvents.full, this.info) + } + } + + /** @inheritDoc */ + protected get type (): PoolType { + return PoolTypes.dynamic } /** @inheritDoc */