X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fthread%2Fdynamic.ts;h=8e795512694aa41a2ea82b9c727e3ebd348b01c9;hb=ecde6ea8c439bbdd9dc2ca118731b5006a1a9884;hp=cf317ca2db497c66ed303184dcc6747237574af6;hpb=9d9fb7b64a28d150583fe1bcd895893f6736d9d4;p=poolifier.git diff --git a/src/pools/thread/dynamic.ts b/src/pools/thread/dynamic.ts index cf317ca2..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,13 +34,20 @@ 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() + return (!this.full && this.internalBusy()) || this.empty + } + + /** @inheritDoc */ + protected checkAndEmitDynamicWorkerCreationEvents (): void { + if (this.full) { + this.emitter?.emit(PoolEvents.full, this.info) + } } /** @inheritDoc */