repositories
/
e-mobility-charging-stations-simulator.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Storage: use worker threads message passing to store performance records from
[e-mobility-charging-stations-simulator.git]
/
src
/
charging-station
/
StationWorker.ts
diff --git
a/src/charging-station/StationWorker.ts
b/src/charging-station/StationWorker.ts
index 20fb27ca04ae47a533f7109525f07a8e7bba1768..dd0f377ceff295c7df8980ece4931d5545dfa9da 100644
(file)
--- a/
src/charging-station/StationWorker.ts
+++ b/
src/charging-station/StationWorker.ts
@@
-1,4
+1,6
@@
-import { StationWorkerData, WorkerEvents } from '../types/Worker';
+// Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
+
+import { StationWorkerData, WorkerEvents, WorkerMessage } from '../types/Worker';
import { parentPort, workerData } from 'worker_threads';
import ChargingStation from './ChargingStation';
import { parentPort, workerData } from 'worker_threads';
import ChargingStation from './ChargingStation';
@@
-19,18
+21,20
@@
if (Utils.workerPoolInUse()) {
}
/**
}
/**
- *
+ *
Listen messages send by the main thread
*/
function addMessageListener(): void {
*/
function addMessageListener(): void {
- parentPort
.on('message', (m
essage) => {
+ parentPort
?.on('message', (message: WorkerM
essage) => {
if (message.id === WorkerEvents.START_WORKER_ELEMENT) {
if (message.id === WorkerEvents.START_WORKER_ELEMENT) {
- startChargingStation(message.
workerD
ata);
+ startChargingStation(message.
d
ata);
}
});
}
/**
}
});
}
/**
- * @param data
+ * Create and start a charging station instance
+ *
+ * @param data workerData
*/
function startChargingStation(data: StationWorkerData): void {
const station = new ChargingStation(data.index, data.templateFile);
*/
function startChargingStation(data: StationWorkerData): void {
const station = new ChargingStation(data.index, data.templateFile);