fix: validate worker node event to wait
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 17 May 2024 13:13:20 +0000 (15:13 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 17 May 2024 13:13:20 +0000 (15:13 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/pools/utils.ts

index df9c256e95390d0731b730ae6726678d5bcbdfb7..c3ca698cac24da378dddf9451031a304b1a5c5a3 100644 (file)
@@ -416,12 +416,20 @@ export const waitWorkerNodeEvents = async <
       resolve(events)
       return
     }
-    workerNode.on(workerNodeEvent, () => {
-      ++events
-      if (events === numberOfEventsToWait) {
-        resolve(events)
-      }
-    })
+    switch (workerNodeEvent) {
+      case 'idle':
+      case 'backPressure':
+      case 'taskFinished':
+        workerNode.on(workerNodeEvent, () => {
+          ++events
+          if (events === numberOfEventsToWait) {
+            resolve(events)
+          }
+        })
+        break
+      default:
+        throw new Error('Invalid worker node event')
+    }
     if (timeout >= 0) {
       setTimeout(() => {
         resolve(events)