From: Jérôme Benoit Date: Sat, 23 Aug 2025 21:22:55 +0000 (+0200) Subject: refactor: cleanup nested conditions X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=4377e4a60ced3b5b91e2592ca573a08ecb2ce188;p=poolifier.git refactor: cleanup nested conditions Signed-off-by: Jérôme Benoit --- diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index d37d21c18..3a1fb9fd9 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -623,12 +623,7 @@ export abstract class AbstractPool< try { await this.destroyWorkerNode(workerNodeKey) } catch (error) { - if ( - this.emitter != null && - this.emitter.listenerCount(PoolEvents.error) > 0 - ) { - this.emitter.emit(PoolEvents.error, error) - } + this.emitter?.emit(PoolEvents.error, error) } }) ) @@ -1127,23 +1122,17 @@ export abstract class AbstractPool< workerNode.registerOnceWorkerEventHandler('error', (error: Error) => { workerNode.info.ready = false this.emitter?.emit(PoolEvents.error, error) - if ( - this.started && - !this.destroying && - this.opts.restartWorkerOnError === true - ) { - if (workerNode.info.dynamic) { - this.createAndSetupDynamicWorkerNode() - } else if (!this.startingMinimumNumberOfWorkers) { - this.startMinimumNumberOfWorkers(true) + if (this.started && !this.destroying) { + if (this.opts.restartWorkerOnError === true) { + if (workerNode.info.dynamic) { + this.createAndSetupDynamicWorkerNode() + } else if (!this.startingMinimumNumberOfWorkers) { + this.startMinimumNumberOfWorkers(true) + } + } + if (this.opts.enableTasksQueue === true) { + this.redistributeQueuedTasks(this.workerNodes.indexOf(workerNode)) } - } - if ( - this.started && - !this.destroying && - this.opts.enableTasksQueue === true - ) { - this.redistributeQueuedTasks(this.workerNodes.indexOf(workerNode)) } // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, promise/no-promise-in-callback workerNode?.terminate().catch((error: unknown) => {