From 207df8aa5381ac3d3ca1f10d9cb79e01593ba10f Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 6 Sep 2024 12:39:38 +0200 Subject: [PATCH] refactor: factor out stealing ratio conditions check into an helper MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/pools/abstract-pool.ts | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index b883eb96..91536f5e 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -240,13 +240,7 @@ export abstract class AbstractPool< if ( this.cannotStealTask() || this.backPressure || - this.opts.tasksQueueOptions?.tasksStealingRatio === 0 || - (this.info.stealingWorkerNodes ?? 0) > - Math.ceil( - this.workerNodes.length * - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - this.opts.tasksQueueOptions!.tasksStealingRatio! - ) + this.isStealingRatioReached() ) { return } @@ -299,14 +293,7 @@ export abstract class AbstractPool< } if ( !workerNode.info.continuousStealing && - (this.cannotStealTask() || - this.opts.tasksQueueOptions?.tasksStealingRatio === 0 || - (this.info.stealingWorkerNodes ?? 0) > - Math.ceil( - this.workerNodes.length * - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - this.opts.tasksQueueOptions!.tasksStealingRatio! - )) + (this.cannotStealTask() || this.isStealingRatioReached()) ) { return } @@ -341,6 +328,18 @@ export abstract class AbstractPool< }) } + private readonly isStealingRatioReached = (): boolean => { + return ( + this.opts.tasksQueueOptions?.tasksStealingRatio === 0 || + (this.info.stealingWorkerNodes ?? 0) > + Math.ceil( + this.workerNodes.length * + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + this.opts.tasksQueueOptions!.tasksStealingRatio! + ) + ) + } + /** * Whether the pool ready event has been emitted or not. */ -- 2.34.1