X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fabstract-pool.ts;h=5eeb57911903587c0760dac8fee11e30407cb86a;hb=a2568a264d9037bf2a1a3f0c146d73d8c5e81c07;hp=0cec96ab5ac277dcb41336a89f3776806c956cc8;hpb=b271fce0078f073d95b4ff2ceae50042b36ce50d;p=poolifier.git diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 0cec96ab..5eeb5791 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -117,6 +117,10 @@ export abstract class AbstractPool< * 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. */ @@ -175,6 +179,7 @@ export abstract class AbstractPool< this.starting = false this.destroying = false this.readyEventEmitted = false + this.startingMinimumNumberOfWorkers = false if (this.opts.startWorkers === true) { this.start() } @@ -953,6 +958,7 @@ export abstract class AbstractPool< * Starts the minimum number of workers. */ private startMinimumNumberOfWorkers (): void { + this.startingMinimumNumberOfWorkers = true while ( this.workerNodes.reduce( (accumulator, workerNode) => @@ -962,6 +968,7 @@ export abstract class AbstractPool< ) { this.createAndSetupWorkerNode() } + this.startingMinimumNumberOfWorkers = false } /** @inheritdoc */ @@ -1251,8 +1258,8 @@ export abstract class AbstractPool< ) { if (workerNode.info.dynamic) { this.createAndSetupDynamicWorkerNode() - } else { - this.createAndSetupWorkerNode() + } else if (!this.startingMinimumNumberOfWorkers) { + this.startMinimumNumberOfWorkers() } } if ( @@ -1273,7 +1280,11 @@ export abstract class AbstractPool< ) workerNode.registerOnceWorkerEventHandler('exit', () => { this.removeWorkerNode(workerNode) - if (this.started && !this.destroying) { + if ( + this.started && + !this.startingMinimumNumberOfWorkers && + !this.destroying + ) { this.startMinimumNumberOfWorkers() } })