-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.
*/
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,
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ this.maximumNumberOfWorkers!
+ )
}
/** @inheritDoc */
- protected get type (): PoolType {
- return PoolTypes.dynamic
+ protected shallCreateDynamicWorker (): boolean {
+ return (
+ (!this.full && this.internalBusy()) ||
+ (this.minimumNumberOfWorkers === 0 && this.workerNodes.length === 0)
+ )
}
/** @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 */