refactor: convert if...then...else to switch...case
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 23 Dec 2023 17:56:31 +0000 (18:56 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 23 Dec 2023 17:56:31 +0000 (18:56 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/pools/worker-node.ts

index d80c03d80f00edc474da050ca41c8297c12142dd..c9ff0e7099a8477f3de03708459e4d485cc1f8f2 100644 (file)
@@ -132,13 +132,16 @@ export class WorkerNode<Worker extends IWorker, Data = unknown>
     })
     this.closeMessageChannel()
     this.removeAllListeners()
-    if (this.info.type === WorkerTypes.thread) {
-      await this.worker.terminate?.()
-    } else if (this.info.type === WorkerTypes.cluster) {
-      this.registerOnceWorkerEventHandler('disconnect', () => {
-        this.worker.kill?.()
-      })
-      this.worker.disconnect?.()
+    switch (this.info.type) {
+      case WorkerTypes.thread:
+        await this.worker.terminate?.()
+        break
+      case WorkerTypes.cluster:
+        this.registerOnceWorkerEventHandler('disconnect', () => {
+          this.worker.kill?.()
+        })
+        this.worker.disconnect?.()
+        break
     }
     await waitWorkerExit
   }