Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
* Listen messages send by the main thread
*/
function addMessageListener(): void {
- parentPort?.on('message', (message: ChargingStationWorkerMessage) => {
+ parentPort?.on('message', async (message: ChargingStationWorkerMessage) => {
if (message.id === ChargingStationWorkerMessageEvents.START_WORKER_ELEMENT) {
startChargingStation(message.data);
+ message.workerOptions?.elementStartDelay > 0 && await Utils.sleep(this.workerOptions.elementStartDelay);
}
});
}
export interface WorkerMessage<T extends WorkerData> {
id: WorkerMessageEvents;
+ workerOptions?: WorkerOptions;
data: T;
}
if (this.getLastWorkerSetElement().numberOfWorkerElements >= this.workerOptions.elementsPerWorker) {
await this.startWorker();
}
- this.getLastWorker().postMessage({ id: WorkerMessageEvents.START_WORKER_ELEMENT, data: elementData });
+ this.getLastWorker().postMessage({ id: WorkerMessageEvents.START_WORKER_ELEMENT, workerOptions: this.workerOptions, data: elementData });
this.getLastWorkerSetElement().numberOfWorkerElements++;
- this.workerOptions.elementStartDelay > 0 && await Utils.sleep(this.workerOptions.elementStartDelay);
}
/**