* Whether the pool is destroying or not.
*/
private destroying: boolean
+ /**
+ * Whether the minimum number of workers is starting or not.
+ */
+ private startingMinimumNumberOfWorkers: boolean
/**
* Whether the pool ready event has been emitted or not.
*/
this.starting = false
this.destroying = false
this.readyEventEmitted = false
+ this.startingMinimumNumberOfWorkers = false
if (this.opts.startWorkers === true) {
this.start()
}
* Starts the minimum number of workers.
*/
private startMinimumNumberOfWorkers (): void {
+ this.startingMinimumNumberOfWorkers = true
while (
this.workerNodes.reduce(
(accumulator, workerNode) =>
) {
this.createAndSetupWorkerNode()
}
+ this.startingMinimumNumberOfWorkers = false
}
/** @inheritdoc */
) {
if (workerNode.info.dynamic) {
this.createAndSetupDynamicWorkerNode()
- } else {
+ } else if (!this.startingMinimumNumberOfWorkers) {
this.startMinimumNumberOfWorkers()
}
}
)
workerNode.registerOnceWorkerEventHandler('exit', () => {
this.removeWorkerNode(workerNode)
- if (this.started && !this.destroying) {
+ if (
+ this.started &&
+ !this.startingMinimumNumberOfWorkers &&
+ !this.destroying
+ ) {
this.startMinimumNumberOfWorkers()
}
})