From 1d7a504ba27c38e3f8617c80cf53aed85da580af Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 23 Mar 2024 00:56:50 +0100 Subject: [PATCH] refactor: cleanup worket set message handling MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/worker/WorkerSet.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/worker/WorkerSet.ts b/src/worker/WorkerSet.ts index 7636a167..1e3000cc 100644 --- a/src/worker/WorkerSet.ts +++ b/src/worker/WorkerSet.ts @@ -153,16 +153,17 @@ export class WorkerSet extends Worke }) worker.on('message', this.workerOptions.poolOptions?.messageHandler ?? EMPTY_FUNCTION) worker.on('message', (message: WorkerMessage) => { - if (this.promiseResponseMap.has(message.uuid)) { + const { uuid, event, data } = message + if (this.promiseResponseMap.has(uuid)) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const { resolve, reject, workerSetElement } = this.promiseResponseMap.get(message.uuid)! - if (message.event === WorkerMessageEvents.addedWorkerElement) { + const { resolve, reject, workerSetElement } = this.promiseResponseMap.get(uuid)! + if (event === WorkerMessageEvents.addedWorkerElement) { this.emitter?.emit(WorkerSetEvents.elementAdded, this.info) workerSetElement.numberOfWorkerElements++ - resolve(message.data) - } else if (message.event === WorkerMessageEvents.workerElementError) { - this.emitter?.emit(WorkerSetEvents.elementError, message.data) - reject(message.data) + resolve(data) + } else if (event === WorkerMessageEvents.workerElementError) { + this.emitter?.emit(WorkerSetEvents.elementError, data) + reject(data) } this.promiseResponseMap.delete(message.uuid) } -- 2.34.1