From: Jérôme Benoit Date: Sun, 17 Sep 2023 18:57:54 +0000 (+0200) Subject: refactor: code cleanup X-Git-Tag: v2.7.0~24 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=9b38ab2d1a0473ecc714895e538a81e381a383ad;p=poolifier.git refactor: code cleanup Signed-off-by: Jérôme Benoit --- diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index e61711a8..cbc24e7d 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -668,6 +668,20 @@ export abstract class AbstractPool< } } + private buildTasksQueueOptions ( + tasksQueueOptions: TasksQueueOptions + ): TasksQueueOptions { + return { + ...{ + size: Math.pow(this.maxSize, 2), + concurrency: 1, + taskStealing: true, + tasksStealingOnBackPressure: true + }, + ...tasksQueueOptions + } + } + private setTasksQueueSize (size: number): void { for (const workerNode of this.workerNodes) { workerNode.tasksQueueBackPressureSize = size @@ -700,20 +714,6 @@ export abstract class AbstractPool< } } - private buildTasksQueueOptions ( - tasksQueueOptions: TasksQueueOptions - ): TasksQueueOptions { - return { - ...{ - size: Math.pow(this.maxSize, 2), - concurrency: 1, - taskStealing: true, - tasksStealingOnBackPressure: true - }, - ...tasksQueueOptions - } - } - /** * Whether the pool is full or not. * @@ -1118,9 +1118,9 @@ export abstract class AbstractPool< this.workerNodes[workerNodeKey].closeChannel() this.emitter?.emit(PoolEvents.error, error) if ( - this.opts.restartWorkerOnError === true && this.started && - !this.starting + !this.starting && + this.opts.restartWorkerOnError === true ) { if (workerInfo.dynamic) { this.createAndSetupDynamicWorkerNode() @@ -1128,7 +1128,7 @@ export abstract class AbstractPool< this.createAndSetupWorkerNode() } } - if (this.opts.enableTasksQueue === true) { + if (this.started && this.opts.enableTasksQueue === true) { this.redistributeQueuedTasks(workerNodeKey) } }) @@ -1396,8 +1396,8 @@ export abstract class AbstractPool< ) workerInfo.ready = message.ready as boolean workerInfo.taskFunctions = message.taskFunctions - if (this.emitter != null && this.ready) { - this.emitter.emit(PoolEvents.ready, this.info) + if (this.ready) { + this.emitter?.emit(PoolEvents.ready, this.info) } }