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
}
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);
}
});
}
static readonly TRANSACTION_DEFAULT_TAGID = '00000000';
static readonly START_WORKER_DELAY = 500;
- static readonly START_WORKER_ELEMENT = 'startWorkerElement';
}
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 {
// 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++;
}