From 3e1416d80bd2640a5fe59cb4bc95c421dcd601d6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 25 Jan 2021 09:44:50 +0100 Subject: [PATCH] Add WorkerEvents enum. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/StationWorker.ts | 8 ++++---- src/utils/Constants.ts | 1 - src/worker/WorkerSet.ts | 3 ++- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/charging-station/StationWorker.ts b/src/charging-station/StationWorker.ts index 32c75ca7..c0e85748 100644 --- a/src/charging-station/StationWorker.ts +++ b/src/charging-station/StationWorker.ts @@ -1,8 +1,8 @@ import { isMainThread, parentPort, workerData } from 'worker_threads'; import ChargingStation from './ChargingStation'; -import Constants from '../utils/Constants'; import Utils from '../utils/Utils'; +import { WorkerEvents } from '../types/WorkerEvents'; if (!isMainThread) { // Add listener to start charging station from main thread @@ -13,9 +13,9 @@ if (!isMainThread) { } function addListener() { - parentPort.on('message', (e) => { - if (e.id === Constants.START_WORKER_ELEMENT) { - startChargingStation(e.workerData); + parentPort.on('message', (message) => { + if (message.id === WorkerEvents.START_WORKER_ELEMENT) { + startChargingStation(message.workerData); } }); } diff --git a/src/utils/Constants.ts b/src/utils/Constants.ts index 5fa60e99..3e002e60 100644 --- a/src/utils/Constants.ts +++ b/src/utils/Constants.ts @@ -36,5 +36,4 @@ export default class Constants { static readonly TRANSACTION_DEFAULT_TAGID = '00000000'; static readonly START_WORKER_DELAY = 500; - static readonly START_WORKER_ELEMENT = 'startWorkerElement'; } diff --git a/src/worker/WorkerSet.ts b/src/worker/WorkerSet.ts index 50b99f02..af753c8f 100644 --- a/src/worker/WorkerSet.ts +++ b/src/worker/WorkerSet.ts @@ -2,6 +2,7 @@ import Constants from '../utils/Constants'; import Utils from '../utils/Utils'; import { Worker } from 'worker_threads'; import WorkerData from '../types/WorkerData'; +import { WorkerEvents } from '../types/WorkerEvents'; import Wrk from './Wrk'; export default class WorkerSet extends Wrk { @@ -41,7 +42,7 @@ export default class WorkerSet extends Wrk { // Start worker sequentially to optimize memory at startup void Utils.sleep(Constants.START_WORKER_DELAY); } - this.getLastWorker().postMessage({ id: Constants.START_WORKER_ELEMENT, workerData: elementData }); + this.getLastWorker().postMessage({ id: WorkerEvents.START_WORKER_ELEMENT, workerData: elementData }); this.lastWorkerNumberOfElements++; } -- 2.34.1