]> Piment Noir Git Repositories - poolifier.git/commitdiff
refactor: cleanup nested conditions
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 23 Aug 2025 21:22:55 +0000 (23:22 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 23 Aug 2025 21:22:55 +0000 (23:22 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/pools/abstract-pool.ts

index d37d21c18d4570ed204b6580ca1d256ebbc2304a..3a1fb9fd951bf2f35d6549c7b38ec3370c6a6424 100644 (file)
@@ -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) => {