From 9b38ab2d1a0473ecc714895e538a81e381a383ad Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 17 Sep 2023 20:57:54 +0200 Subject: [PATCH] refactor: code cleanup 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 | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) 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) } } -- 2.34.1