From: Jérôme Benoit Date: Fri, 22 Mar 2024 23:56:50 +0000 (+0100) Subject: refactor: cleanup worket set message handling X-Git-Tag: v1.3.1~10 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=1d7a504ba27c38e3f8617c80cf53aed85da580af;p=e-mobility-charging-stations-simulator.git refactor: cleanup worket set message handling Signed-off-by: Jérôme Benoit --- 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) }