From: Jérôme Benoit Date: Fri, 6 Sep 2024 10:39:38 +0000 (+0200) Subject: refactor: factor out stealing ratio conditions check into an helper X-Git-Tag: v4.2.10~2 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=207df8aa5381ac3d3ca1f10d9cb79e01593ba10f;p=poolifier.git refactor: factor out stealing ratio conditions check into an helper Signed-off-by: Jérôme Benoit --- 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. */