X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fthread%2Fdynamic.ts;h=8e795512694aa41a2ea82b9c727e3ebd348b01c9;hb=9ef62ae7a28438954d80d0a1ffb23cee05dfbe2d;hp=cd9d23253a040f44070da2fe0b0504da31aeb283;hpb=2889bd70182e9e42c75d686ece3c288307e01d4f;p=poolifier.git diff --git a/src/pools/thread/dynamic.ts b/src/pools/thread/dynamic.ts index cd9d2325..8e795512 100644 --- a/src/pools/thread/dynamic.ts +++ b/src/pools/thread/dynamic.ts @@ -1,6 +1,6 @@ -import { type PoolType, PoolTypes } from '../pool' -import { checkDynamicPoolSize } from '../utils' -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. @@ -34,10 +34,22 @@ export class DynamicThreadPool< 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