Response
>
+ /**
+ * Dynamic pool maximum size property placeholder.
+ */
+ protected readonly max?: number
+
/**
* Whether the pool is starting or not.
*/
this.chooseWorkerNode = this.chooseWorkerNode.bind(this)
this.executeTask = this.executeTask.bind(this)
this.enqueueTask = this.enqueueTask.bind(this)
- this.dequeueTask = this.dequeueTask.bind(this)
- this.checkAndEmitTaskExecutionEvents =
- this.checkAndEmitTaskExecutionEvents.bind(this)
- this.checkAndEmitTaskQueuingEvents =
- this.checkAndEmitTaskQueuingEvents.bind(this)
if (this.opts.enableEvents === true) {
this.emitter = new PoolEmitter()
tasksQueueOptions.concurrency <= 0
) {
throw new Error(
- `Invalid worker tasks concurrency '${tasksQueueOptions.concurrency}' is a negative integer or zero`
+ `Invalid worker tasks concurrency: ${tasksQueueOptions.concurrency} is a negative integer or zero`
)
}
}
/**
* The pool minimum size.
*/
- protected abstract get minSize (): number
+ protected get minSize (): number {
+ return this.numberOfWorkers
+ }
/**
* The pool maximum size.
*/
- protected abstract get maxSize (): number
+ protected get maxSize (): number {
+ return this.max ?? this.numberOfWorkers
+ }
/**
* Checks if the worker id sent in the received message from a worker is valid.
await this.destroyWorkerNode(workerNodeKey)
})
)
- this.emitter?.emit(PoolEvents.destroy)
+ this.emitter?.emit(PoolEvents.destroy, this.info)
}
protected async sendKillMessageToWorker (
if (this.workerChoiceStrategyContext.getStrategyPolicy().useDynamicWorker) {
workerInfo.ready = true
}
+ this.checkAndEmitDynamicWorkerCreationEvents()
return workerNodeKey
}
}
private checkAndEmitTaskExecutionEvents (): void {
- if (this.emitter != null) {
- if (this.busy) {
- this.emitter.emit(PoolEvents.busy, this.info)
- }
- if (this.type === PoolTypes.dynamic && this.full) {
- this.emitter.emit(PoolEvents.full, this.info)
- }
+ if (this.busy) {
+ this.emitter?.emit(PoolEvents.busy, this.info)
}
}
}
}
+ private checkAndEmitDynamicWorkerCreationEvents (): void {
+ if (this.type === PoolTypes.dynamic) {
+ if (this.full) {
+ this.emitter?.emit(PoolEvents.full, this.info)
+ }
+ }
+ }
+
/**
* Gets the worker information given its worker node key.
*