// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
-import { AsyncResource } from 'node:async_hooks';
import { parentPort } from 'node:worker_threads';
import { ThreadWorker } from 'poolifier';
import { BaseError } from '../exception';
import type { ChargingStationWorkerData } from '../types';
import { Configuration } from '../utils';
-import { type WorkerData, type WorkerMessage, WorkerMessageEvents } from '../worker';
-
-const moduleName = 'ChargingStationWorker';
+import { type WorkerMessage, WorkerMessageEvents } from '../worker';
/**
* Creates and starts a charging station instance
new ChargingStation(data!.index, data!.templateFile).start();
};
-class ChargingStationWorker<Data extends WorkerData> extends AsyncResource {
+class ChargingStationWorker<Data extends ChargingStationWorkerData> {
constructor() {
- super(moduleName);
// Add message listener to create and start charging station from the main thread
parentPort?.on('message', (message: WorkerMessage<Data>) => {
switch (message.event) {
case WorkerMessageEvents.startWorkerElement:
try {
- this.runInAsyncScope(
- startChargingStation.bind(this) as (data?: Data) => void,
- this,
- message.data,
- );
+ startChargingStation(message.data);
parentPort?.postMessage({
event: WorkerMessageEvents.startedWorkerElement,
});