From ca0da0da5f4dc739572c835d6e53e40de3a42382 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 11 Dec 2023 13:49:21 +0100 Subject: [PATCH] perf: a charging station worker is not an AsyncResource MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ChargingStationWorker.ts | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/charging-station/ChargingStationWorker.ts b/src/charging-station/ChargingStationWorker.ts index 955ce933..d9e462d0 100644 --- a/src/charging-station/ChargingStationWorker.ts +++ b/src/charging-station/ChargingStationWorker.ts @@ -1,6 +1,5 @@ // 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'; @@ -9,9 +8,7 @@ import { ChargingStation } from './ChargingStation'; 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 @@ -22,19 +19,14 @@ const startChargingStation = (data?: ChargingStationWorkerData): void => { new ChargingStation(data!.index, data!.templateFile).start(); }; -class ChargingStationWorker extends AsyncResource { +class ChargingStationWorker { constructor() { - super(moduleName); // Add message listener to create and start charging station from the main thread parentPort?.on('message', (message: WorkerMessage) => { 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, }); -- 2.34.1