From 59b6ed8d1db313ef3371efd8ab5e039cf3dedab0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 25 Feb 2023 22:32:48 +0100 Subject: [PATCH] refactor(simulator): constify and factor out empty data structure definitions MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../AutomaticTransactionGenerator.ts | 4 +-- src/charging-station/ChargingStation.ts | 11 +++++--- .../ChargingStationConfigurationUtils.ts | 4 +-- src/charging-station/ChargingStationUtils.ts | 2 +- .../ocpp/1.6/OCPP16IncomingRequestService.ts | 28 +++++-------------- .../ocpp/1.6/OCPP16ResponseService.ts | 2 +- .../ocpp/1.6/OCPP16ServiceUtils.ts | 10 ++++--- .../ocpp/2.0/OCPP20ResponseService.ts | 4 +-- src/charging-station/ocpp/OCPPConstants.ts | 5 ++-- .../ocpp/OCPPRequestService.ts | 6 ++-- .../ui-server/UIHttpServer.ts | 14 ++++++---- .../ui-server/UIWebSocketServer.ts | 9 ++---- src/exception/OCPPError.ts | 3 +- src/performance/PerformanceStatistics.ts | 2 +- src/performance/storage/JsonFileStorage.ts | 6 ++-- src/utils/Constants.ts | 6 ++++ src/worker/WorkerAbstract.ts | 6 ++-- src/worker/WorkerConstants.ts | 5 ++++ src/worker/WorkerFactory.ts | 5 ++-- src/worker/WorkerSet.ts | 10 +++---- 20 files changed, 69 insertions(+), 73 deletions(-) diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index 26b3a2a2..4185215a 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -101,9 +101,7 @@ export class AutomaticTransactionGenerator extends AsyncResource { ) => Promise, this, connectorId - ).catch(() => { - /* This is intentional */ - }); + ).catch(Constants.EMPTY_FUNCTION); } else if (this.connectorsStatus.get(connectorId)?.start === true) { logger.warn(`${this.logPrefix(connectorId)} is already started on connector`); } diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 23724e79..f57aebed 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -625,7 +625,7 @@ export class ChargingStation { } public openWSConnection( - options: WsOptions = this.stationInfo?.wsOptions ?? {}, + options: WsOptions = this.stationInfo?.wsOptions ?? Constants.EMPTY_OBJECT, params: { closeOpened?: boolean; terminateOpened?: boolean } = { closeOpened: false, terminateOpened: false, @@ -902,7 +902,7 @@ export class ChargingStation { }, reset: true, }, - stationTemplate?.firmwareUpgrade ?? {} + stationTemplate?.firmwareUpgrade ?? Constants.EMPTY_OBJECT ); stationInfo.resetTime = !Utils.isNullOrUndefined(stationTemplate?.resetTime) ? stationTemplate.resetTime * 1000 @@ -1362,7 +1362,7 @@ export class ChargingStation { fs.mkdirSync(path.dirname(this.configurationFile), { recursive: true }); } const configurationData: ChargingStationConfiguration = - Utils.cloneObject(this.getConfigurationFromFile()) ?? {}; + Utils.cloneObject(this.getConfigurationFromFile()) ?? Constants.EMPTY_OBJECT; this.ocppConfiguration?.configurationKey && (configurationData.configurationKey = this.ocppConfiguration.configurationKey); this.stationInfo && (configurationData.stationInfo = this.stationInfo); @@ -2043,7 +2043,10 @@ export class ChargingStation { `${this.logPrefix()} WebSocket connection retry #${this.autoReconnectRetryCount.toString()}` ); this.openWSConnection( - { ...(this.stationInfo?.wsOptions ?? {}), handshakeTimeout: reconnectTimeout }, + { + ...(this.stationInfo?.wsOptions ?? Constants.EMPTY_OBJECT), + handshakeTimeout: reconnectTimeout, + }, { closeOpened: true } ); this.wsConnectionRestarted = true; diff --git a/src/charging-station/ChargingStationConfigurationUtils.ts b/src/charging-station/ChargingStationConfigurationUtils.ts index 579e2ab4..5e14e458 100644 --- a/src/charging-station/ChargingStationConfigurationUtils.ts +++ b/src/charging-station/ChargingStationConfigurationUtils.ts @@ -1,6 +1,6 @@ import type { ChargingStation } from './internal'; import type { ConfigurationKey, ConfigurationKeyType } from '../types'; -import { logger } from '../utils'; +import { Constants, logger } from '../utils'; type ConfigurationKeyOptions = { readonly?: boolean; visible?: boolean; reboot?: boolean }; type DeleteConfigurationKeyParams = { save?: boolean; caseInsensitive?: boolean }; @@ -35,7 +35,7 @@ export class ChargingStationConfigurationUtils { }, params: AddConfigurationKeyParams = { overwrite: false, save: false } ): void { - options = options ?? ({} as ConfigurationKeyOptions); + options = options ?? (Constants.EMPTY_OBJECT as ConfigurationKeyOptions); options.readonly = options?.readonly ?? false; options.visible = options?.visible ?? true; options.reboot = options?.reboot ?? false; diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index 74ec5390..22e712d0 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -263,7 +263,7 @@ export class ChargingStationUtils { randomSerialNumber: true, } ): void { - params = params ?? {}; + params = params ?? Constants.EMPTY_OBJECT; params.randomSerialNumberUpperCase = params?.randomSerialNumberUpperCase ?? true; params.randomSerialNumber = params?.randomSerialNumber ?? true; const serialNumberSuffix = params?.randomSerialNumber diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 9424fcf2..1179d425 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -358,9 +358,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { ) => Promise, chargingStation, `${commandPayload.type}Reset` as OCPP16StopTransactionReason - ).catch(() => { - /* This is intentional */ - }); + ).catch(Constants.EMPTY_FUNCTION); logger.info( `${chargingStation.logPrefix()} ${ commandPayload.type @@ -977,14 +975,10 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { ) => Promise, this, chargingStation - ).catch(() => { - /* This is intentional */ - }); + ).catch(Constants.EMPTY_FUNCTION); } else { setTimeout(() => { - this.updateFirmware(chargingStation).catch(() => { - /* Intentional */ - }); + this.updateFirmware(chargingStation).catch(Constants.EMPTY_FUNCTION); }, retrieveDate?.getTime() - now); } return OCPPConstants.OCPP_RESPONSE_EMPTY; @@ -1218,9 +1212,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { .then((response) => { chargingStation.bootNotificationResponse = response; }) - .catch(() => { - /* This is intentional */ - }); + .catch(Constants.EMPTY_FUNCTION); }, Constants.OCPP_TRIGGER_MESSAGE_DELAY); return OCPPConstants.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED; case OCPP16MessageTrigger.Heartbeat: @@ -1234,9 +1226,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { triggerMessage: true, } ) - .catch(() => { - /* This is intentional */ - }); + .catch(Constants.EMPTY_FUNCTION); }, Constants.OCPP_TRIGGER_MESSAGE_DELAY); return OCPPConstants.OCPP_TRIGGER_MESSAGE_RESPONSE_ACCEPTED; case OCPP16MessageTrigger.StatusNotification: @@ -1255,9 +1245,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { triggerMessage: true, } ) - .catch(() => { - /* This is intentional */ - }); + .catch(Constants.EMPTY_FUNCTION); } else { for (const connectorId of chargingStation.connectors.keys()) { chargingStation.ocppRequestService @@ -1276,9 +1264,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { triggerMessage: true, } ) - .catch(() => { - /* This is intentional */ - }); + .catch(Constants.EMPTY_FUNCTION); } } }, Constants.OCPP_TRIGGER_MESSAGE_DELAY); diff --git a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts index 6997e3d8..df8a02e8 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts @@ -353,7 +353,7 @@ export class OCPP16ResponseService extends OCPPResponseService { chargingStation, OCPP16StandardParametersKey.HeartbeatInterval, payload.interval.toString(), - {}, + Constants.EMPTY_OBJECT, { overwrite: true, save: true } ); ChargingStationConfigurationUtils.addConfigurationKey( diff --git a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts index 50f6b925..907cee32 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts @@ -196,7 +196,8 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { connectorId, OCPP16MeterValueMeasurand.POWER_ACTIVE_IMPORT ); - let powerPerPhaseSampledValueTemplates: MeasurandPerPhaseSampledValueTemplates = {}; + let powerPerPhaseSampledValueTemplates: MeasurandPerPhaseSampledValueTemplates = + Constants.EMPTY_OBJECT; if (chargingStation.getNumberOfPhases() === 3) { powerPerPhaseSampledValueTemplates = { L1: OCPP16ServiceUtils.getSampledValueTemplate( @@ -233,7 +234,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { powerSampledValueTemplate.measurand ?? OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER } measurand value`; - const powerMeasurandValues = {} as MeasurandValues; + const powerMeasurandValues = Constants.EMPTY_OBJECT as MeasurandValues; const unitDivider = powerSampledValueTemplate?.unit === MeterValueUnit.KILO_WATT ? 1000 : 1; const connectorMaximumAvailablePower = chargingStation.getConnectorMaximumAvailablePower(connectorId); @@ -403,7 +404,8 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { connectorId, OCPP16MeterValueMeasurand.CURRENT_IMPORT ); - let currentPerPhaseSampledValueTemplates: MeasurandPerPhaseSampledValueTemplates = {}; + let currentPerPhaseSampledValueTemplates: MeasurandPerPhaseSampledValueTemplates = + Constants.EMPTY_OBJECT; if (chargingStation.getNumberOfPhases() === 3) { currentPerPhaseSampledValueTemplates = { L1: OCPP16ServiceUtils.getSampledValueTemplate( @@ -440,7 +442,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { currentSampledValueTemplate.measurand ?? OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER } measurand value`; - const currentMeasurandValues: MeasurandValues = {} as MeasurandValues; + const currentMeasurandValues: MeasurandValues = Constants.EMPTY_OBJECT as MeasurandValues; const connectorMaximumAvailablePower = chargingStation.getConnectorMaximumAvailablePower(connectorId); let connectorMaximumAmperage: number; diff --git a/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts b/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts index 6772fd46..eb6c00c3 100644 --- a/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts +++ b/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts @@ -19,7 +19,7 @@ import { RegistrationStatusEnumType, type ResponseHandler, } from '../../../types'; -import { logger } from '../../../utils'; +import { Constants, logger } from '../../../utils'; import { OCPP20ServiceUtils, OCPPResponseService } from '../internal'; const moduleName = 'OCPP20ResponseService'; @@ -161,7 +161,7 @@ export class OCPP20ResponseService extends OCPPResponseService { chargingStation, OCPP20OptionalVariableName.HeartbeatInterval, payload.interval.toString(), - {}, + Constants.EMPTY_OBJECT, { overwrite: true, save: true } ); chargingStation.heartbeatSetInterval diff --git a/src/charging-station/ocpp/OCPPConstants.ts b/src/charging-station/ocpp/OCPPConstants.ts index 1064a95a..c8b110e4 100644 --- a/src/charging-station/ocpp/OCPPConstants.ts +++ b/src/charging-station/ocpp/OCPPConstants.ts @@ -8,10 +8,11 @@ import { TriggerMessageStatus, UnlockStatus, } from '../../types'; +import { Constants } from '../../utils'; export class OCPPConstants { - static readonly OCPP_REQUEST_EMPTY = Object.freeze({}); - static readonly OCPP_RESPONSE_EMPTY = Object.freeze({}); + static readonly OCPP_REQUEST_EMPTY = Constants.EMPTY_FREEZED_OBJECT; + static readonly OCPP_RESPONSE_EMPTY = Constants.EMPTY_FREEZED_OBJECT; static readonly OCPP_RESPONSE_ACCEPTED = Object.freeze({ status: GenericStatus.Accepted }); static readonly OCPP_RESPONSE_REJECTED = Object.freeze({ status: GenericStatus.Rejected }); diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index 0f05d9a3..4115eff1 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -275,7 +275,7 @@ export abstract class OCPPRequestService { ErrorType.GENERIC_ERROR, `WebSocket closed or errored for buffered message id '${messageId}' with content '${messageToSend}'`, commandName, - (messagePayload as JsonObject)?.details ?? {} + (messagePayload as JsonObject)?.details ?? Constants.EMPTY_FREEZED_OBJECT ) ); } else if (wsClosedOrErrored) { @@ -283,7 +283,7 @@ export abstract class OCPPRequestService { ErrorType.GENERIC_ERROR, `WebSocket closed or errored for non buffered message id '${messageId}' with content '${messageToSend}'`, commandName, - (messagePayload as JsonObject)?.details ?? {} + (messagePayload as JsonObject)?.details ?? Constants.EMPTY_FREEZED_OBJECT ); // Reject response if (messageType !== MessageType.CALL_MESSAGE) { @@ -358,7 +358,7 @@ export abstract class OCPPRequestService { ErrorType.GENERIC_ERROR, `Timeout for message id '${messageId}'`, commandName, - (messagePayload as JsonObject)?.details ?? {} + (messagePayload as JsonObject)?.details ?? Constants.EMPTY_FREEZED_OBJECT ), () => { messageType === MessageType.CALL_MESSAGE && chargingStation.requests.delete(messageId); diff --git a/src/charging-station/ui-server/UIHttpServer.ts b/src/charging-station/ui-server/UIHttpServer.ts index 186669ef..9e333026 100644 --- a/src/charging-station/ui-server/UIHttpServer.ts +++ b/src/charging-station/ui-server/UIHttpServer.ts @@ -13,7 +13,7 @@ import { ResponseStatus, type UIServerConfiguration, } from '../../types'; -import { Utils, logger } from '../../utils'; +import { Constants, Utils, logger } from '../../utils'; import { AbstractUIServer, UIServerUtils } from '../internal'; const moduleName = 'UIHttpServer'; @@ -117,10 +117,14 @@ export class UIHttpServer extends AbstractUIServer { const body = JSON.parse(Buffer.concat(bodyBuffer).toString()) as RequestPayload; this.uiServices .get(version) - ?.requestHandler(this.buildProtocolRequest(uuid, procedureName, body ?? {})) - .catch(() => { - /* Error caught by AbstractUIService */ - }); + ?.requestHandler( + this.buildProtocolRequest( + uuid, + procedureName, + body ?? Constants.EMPTY_FREEZED_OBJECT + ) + ) + .catch(Constants.EMPTY_FUNCTION); }); } else { throw new BaseError(`Unsupported HTTP method: '${req.method}'`); diff --git a/src/charging-station/ui-server/UIWebSocketServer.ts b/src/charging-station/ui-server/UIWebSocketServer.ts index 291e9263..bf9eb8b3 100644 --- a/src/charging-station/ui-server/UIWebSocketServer.ts +++ b/src/charging-station/ui-server/UIWebSocketServer.ts @@ -10,7 +10,7 @@ import { type UIServerConfiguration, WebSocketCloseEventStatusCode, } from '../../types'; -import { Utils, logger } from '../../utils'; +import { Constants, Utils, logger } from '../../utils'; import { AbstractUIServer, UIServerUtils } from '../internal'; const moduleName = 'UIWebSocketServer'; @@ -48,12 +48,7 @@ export class UIWebSocketServer extends AbstractUIServer { } const [requestId] = request as ProtocolRequest; this.responseHandlers.set(requestId, ws); - this.uiServices - .get(version) - ?.requestHandler(request) - .catch(() => { - /* Error caught by AbstractUIService */ - }); + this.uiServices.get(version)?.requestHandler(request).catch(Constants.EMPTY_FUNCTION); }); ws.on('error', (error) => { logger.error(`${this.logPrefix(moduleName, 'start.ws.onerror')} WebSocket error:`, error); diff --git a/src/exception/OCPPError.ts b/src/exception/OCPPError.ts index 3b23cc3b..c5d25ddc 100644 --- a/src/exception/OCPPError.ts +++ b/src/exception/OCPPError.ts @@ -7,6 +7,7 @@ import { type JsonType, type RequestCommand, } from '../types'; +import { Constants } from '../utils'; export class OCPPError extends BaseError { code: ErrorType; @@ -23,6 +24,6 @@ export class OCPPError extends BaseError { this.code = code ?? ErrorType.GENERIC_ERROR; this.command = command; - this.details = details ?? {}; + this.details = details ?? Constants.EMPTY_FREEZED_OBJECT; } } diff --git a/src/performance/PerformanceStatistics.ts b/src/performance/PerformanceStatistics.ts index 69829ff1..956b8d36 100644 --- a/src/performance/PerformanceStatistics.ts +++ b/src/performance/PerformanceStatistics.ts @@ -226,7 +226,7 @@ export class PerformanceStatistics { const entryName = entry.name; // Initialize command statistics if (!this.statistics.statisticsData.has(entryName)) { - this.statistics.statisticsData.set(entryName, {}); + this.statistics.statisticsData.set(entryName, Constants.EMPTY_OBJECT); } // Update current statistics this.statistics.updatedAt = new Date(); diff --git a/src/performance/storage/JsonFileStorage.ts b/src/performance/storage/JsonFileStorage.ts index 44340cc4..fcb35a4d 100644 --- a/src/performance/storage/JsonFileStorage.ts +++ b/src/performance/storage/JsonFileStorage.ts @@ -5,7 +5,7 @@ import fs from 'node:fs'; import lockfile from 'proper-lockfile'; import { FileType, type Statistics } from '../../types'; -import { FileUtils, Utils } from '../../utils'; +import { Constants, FileUtils, Utils } from '../../utils'; import { Storage } from '../internal'; export class JsonFileStorage extends Storage { @@ -42,9 +42,7 @@ export class JsonFileStorage extends Storage { } await release(); }) - .catch(() => { - /* This is intentional */ - }); + .catch(Constants.EMPTY_FUNCTION); } public open(): void { diff --git a/src/utils/Constants.ts b/src/utils/Constants.ts index 246aa788..67b40146 100644 --- a/src/utils/Constants.ts +++ b/src/utils/Constants.ts @@ -47,6 +47,12 @@ export class Constants { static readonly MAX_RANDOM_INTEGER = 281474976710654; + static EMPTY_OBJECT = {}; + static readonly EMPTY_FREEZED_OBJECT = Object.freeze({}); + static readonly EMPTY_FUNCTION = Object.freeze(() => { + /* This is intentional */ + }); + private constructor() { // This is intentional } diff --git a/src/worker/WorkerAbstract.ts b/src/worker/WorkerAbstract.ts index f6777948..2803eea4 100644 --- a/src/worker/WorkerAbstract.ts +++ b/src/worker/WorkerAbstract.ts @@ -23,10 +23,8 @@ export abstract class WorkerAbstract { poolMinSize: WorkerConstants.DEFAULT_POOL_MIN_SIZE, poolMaxSize: WorkerConstants.DEFAULT_POOL_MAX_SIZE, elementsPerWorker: WorkerConstants.DEFAULT_ELEMENTS_PER_WORKER, - poolOptions: {}, - messageHandler: () => { - /* This is intentional */ - }, + poolOptions: WorkerConstants.EMPTY_OBJECT, + messageHandler: WorkerConstants.EMPTY_FUNCTION, } ) { if (!workerScript) { diff --git a/src/worker/WorkerConstants.ts b/src/worker/WorkerConstants.ts index 8e34a165..12bb70ac 100644 --- a/src/worker/WorkerConstants.ts +++ b/src/worker/WorkerConstants.ts @@ -1,4 +1,9 @@ export class WorkerConstants { + public static EMPTY_OBJECT = {}; + public static readonly EMPTY_FUNCTION = Object.freeze(() => { + /* This is intentional */ + }); + static readonly DEFAULT_ELEMENT_START_DELAY = 0; static readonly DEFAULT_WORKER_START_DELAY = 500; static readonly POOL_MAX_INACTIVE_TIME = 60000; diff --git a/src/worker/WorkerFactory.ts b/src/worker/WorkerFactory.ts index e590ad14..ff13b80f 100644 --- a/src/worker/WorkerFactory.ts +++ b/src/worker/WorkerFactory.ts @@ -22,12 +22,13 @@ export class WorkerFactory { if (!isMainThread) { throw new Error('Cannot get a worker implementation outside the main thread'); } - workerOptions = workerOptions ?? ({} as WorkerOptions); + workerOptions = workerOptions ?? (WorkerConstants.EMPTY_OBJECT as WorkerOptions); workerOptions.workerStartDelay = workerOptions?.workerStartDelay ?? WorkerConstants.DEFAULT_WORKER_START_DELAY; workerOptions.elementStartDelay = workerOptions?.elementStartDelay ?? WorkerConstants.DEFAULT_ELEMENT_START_DELAY; - workerOptions.poolOptions = workerOptions?.poolOptions ?? ({} as PoolOptions); + workerOptions.poolOptions = + workerOptions?.poolOptions ?? (WorkerConstants.EMPTY_OBJECT as PoolOptions); workerOptions?.messageHandler && (workerOptions.poolOptions.messageHandler = workerOptions.messageHandler); let workerImplementation: WorkerAbstract | null = null; diff --git a/src/worker/WorkerSet.ts b/src/worker/WorkerSet.ts index a8a06a39..b8507d53 100644 --- a/src/worker/WorkerSet.ts +++ b/src/worker/WorkerSet.ts @@ -3,6 +3,7 @@ import { Worker } from 'node:worker_threads'; import { WorkerAbstract } from './WorkerAbstract'; +import { WorkerConstants } from './WorkerConstants'; import { type MessageHandler, type WorkerData, @@ -89,12 +90,9 @@ export class WorkerSet extends WorkerAbstract { const worker = new Worker(this.workerScript); worker.on( 'message', - ( - this.workerOptions?.messageHandler ?? - (() => { - /* This is intentional */ - }) - ).bind(this) as MessageHandler + (this.workerOptions?.messageHandler ?? WorkerConstants.EMPTY_FUNCTION).bind( + this + ) as MessageHandler ); worker.on('error', WorkerUtils.defaultErrorHandler.bind(this) as (err: Error) => void); worker.on('exit', (code) => { -- 2.34.1