From: Jérôme Benoit Date: Fri, 17 May 2024 13:13:20 +0000 (+0200) Subject: fix: validate worker node event to wait X-Git-Tag: v4.0.9~8 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=2ef26de4e268829f5d0b591c135a44f4d16ae5bb;p=poolifier.git fix: validate worker node event to wait Signed-off-by: Jérôme Benoit --- diff --git a/src/pools/utils.ts b/src/pools/utils.ts index df9c256e..c3ca698c 100644 --- a/src/pools/utils.ts +++ b/src/pools/utils.ts @@ -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)