public readonly connectorsStatus: Map<number, Status>;
public started: boolean;
+ private starting: boolean;
+ private stopping: boolean;
private readonly chargingStation: ChargingStation;
private constructor(chargingStation: ChargingStation) {
super(moduleName);
this.started = false;
+ this.starting = false;
+ this.stopping = false;
this.chargingStation = chargingStation;
this.connectorsStatus = new Map<number, Status>();
this.initializeConnectorsStatus();
logger.warn(`${this.logPrefix()} is already started`);
return;
}
+ if (this.starting === true) {
+ logger.warn(`${this.logPrefix()} is already starting`);
+ return;
+ }
+ this.starting = true;
this.startConnectors();
this.started = true;
+ this.starting = false;
}
public stop(): void {
logger.warn(`${this.logPrefix()} is already stopped`);
return;
}
+ if (this.stopping === true) {
+ logger.warn(`${this.logPrefix()} is already stopping`);
+ return;
+ }
+ this.stopping = true;
this.stopConnectors();
this.started = false;
+ this.stopping = false;
}
public startConnector(connectorId: number): void {
import { Configuration } from '../utils';
import { WorkerConstants, type WorkerMessage, WorkerMessageEvents } from '../worker';
+const moduleName = 'ChargingStationWorker';
+
/**
* Create and start a charging station instance
*
class ChargingStationWorker extends AsyncResource {
constructor() {
- super('ChargingStationWorker');
+ super(moduleName);
// Add message listener to create and start charging station from the main thread
parentPort?.on('message', (message: WorkerMessage<ChargingStationWorkerData>) => {
if (message.id === WorkerMessageEvents.startWorkerElement) {