From 8434025b7338b3439180ed7c2bed888fc42e04d3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 26 Jan 2021 20:11:06 +0100 Subject: [PATCH] Use generic for worker data type. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/start.ts | 2 +- src/utils/Statistics.ts | 2 +- src/worker/WorkerDynamicPool.ts | 4 ++-- src/worker/WorkerFactory.ts | 8 ++++---- src/worker/WorkerSet.ts | 6 +++--- src/worker/WorkerStaticPool.ts | 4 ++-- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/start.ts b/src/start.ts index 04dd2814..265b1fb0 100644 --- a/src/start.ts +++ b/src/start.ts @@ -8,7 +8,7 @@ class Bootstrap { static async start() { try { let numStationsTotal = 0; - const workerImplementation: Wrk = WorkerFactory.getWorkerImpl('./dist/charging-station/StationWorker.js', Configuration.getWorkerProcess(), { + const workerImplementation: Wrk = WorkerFactory.getWorkerImpl('./dist/charging-station/StationWorker.js', Configuration.getWorkerProcess(), { poolMaxSize: Configuration.getWorkerPoolMaxSize(), poolMinSize: Configuration.getWorkerPoolMinSize(), elementsPerWorker: Configuration.getChargingStationsPerWorker() diff --git a/src/utils/Statistics.ts b/src/utils/Statistics.ts index 05a22551..2aa99b0d 100644 --- a/src/utils/Statistics.ts +++ b/src/utils/Statistics.ts @@ -14,7 +14,7 @@ export default class Statistics { public constructor(objName: string) { this.objId = objName; - this.commandsStatistics = { id: this.objId ? this.objId : ' Object id not specified', commandsStatisticsData: {} }; + this.commandsStatistics = { id: this.objId ? this.objId : 'Object id not specified', commandsStatisticsData: {} }; } public addMessage(command: RequestCommand | IncomingRequestCommand, messageType: MessageType): void { diff --git a/src/worker/WorkerDynamicPool.ts b/src/worker/WorkerDynamicPool.ts index 570e5d1b..4410aa3a 100644 --- a/src/worker/WorkerDynamicPool.ts +++ b/src/worker/WorkerDynamicPool.ts @@ -5,7 +5,7 @@ import Utils from '../utils/Utils'; import { WorkerData } from '../types/Worker'; import Wrk from './Wrk'; -export default class WorkerDynamicPool extends Wrk { +export default class WorkerDynamicPool extends Wrk { private pool: DynamicPool; /** @@ -39,7 +39,7 @@ export default class WorkerDynamicPool extends Wrk { * @return {Promise} * @public */ - public async addElement(elementData: WorkerData): Promise { + public async addElement(elementData: T): Promise { await this.pool.execute(elementData); // Start worker sequentially to optimize memory at startup await Utils.sleep(Constants.START_WORKER_DELAY); diff --git a/src/worker/WorkerFactory.ts b/src/worker/WorkerFactory.ts index 24145627..d71e4227 100644 --- a/src/worker/WorkerFactory.ts +++ b/src/worker/WorkerFactory.ts @@ -7,7 +7,7 @@ import WorkerStaticPool from './WorkerStaticPool'; import Wrk from './Wrk'; export default class WorkerFactory { - public static getWorkerImpl(workerScript: string, workerProcessType: WorkerProcessType, options?: WorkerOptions): Wrk { + public static getWorkerImpl(workerScript: string, workerProcessType: WorkerProcessType, options?: WorkerOptions): Wrk { if (Utils.isUndefined(options)) { options = {} as WorkerOptions; } @@ -16,12 +16,12 @@ export default class WorkerFactory { if (Utils.isUndefined(options.elementsPerWorker)) { options.elementsPerWorker = 1; } - return new WorkerSet(workerScript, options.elementsPerWorker); + return new WorkerSet(workerScript, options.elementsPerWorker); case WorkerProcessType.STATIC_POOL: if (Utils.isUndefined(options.poolMaxSize)) { options.elementsPerWorker = 16; } - return new WorkerStaticPool(workerScript, options.poolMaxSize); + return new WorkerStaticPool(workerScript, options.poolMaxSize); case WorkerProcessType.DYNAMIC_POOL: if (Utils.isUndefined(options.poolMinSize)) { options.elementsPerWorker = 4; @@ -29,7 +29,7 @@ export default class WorkerFactory { if (Utils.isUndefined(options.poolMaxSize)) { options.elementsPerWorker = 16; } - return new WorkerDynamicPool(workerScript, options.poolMinSize, options.poolMaxSize); + return new WorkerDynamicPool(workerScript, options.poolMinSize, options.poolMaxSize); default: return null; } diff --git a/src/worker/WorkerSet.ts b/src/worker/WorkerSet.ts index 0c59c091..0fd54fb2 100644 --- a/src/worker/WorkerSet.ts +++ b/src/worker/WorkerSet.ts @@ -1,11 +1,11 @@ -import { WorkerData, WorkerEvents, WorkerSetElement } from '../types/Worker'; +import { WorkerEvents, WorkerSetElement } from '../types/Worker'; import Constants from '../utils/Constants'; import Utils from '../utils/Utils'; import { Worker } from 'worker_threads'; import Wrk from './Wrk'; -export default class WorkerSet extends Wrk { +export default class WorkerSet extends Wrk { public maxElementsPerWorker: number; private workers: Set; @@ -30,7 +30,7 @@ export default class WorkerSet extends Wrk { * @return {Promise} * @public */ - public async addElement(elementData: WorkerData): Promise { + public async addElement(elementData: T): Promise { if (!this.workers) { throw Error('Cannot add a WorkerSet element: workers\' set does not exist'); } diff --git a/src/worker/WorkerStaticPool.ts b/src/worker/WorkerStaticPool.ts index 9c2bc41d..c6625d8b 100644 --- a/src/worker/WorkerStaticPool.ts +++ b/src/worker/WorkerStaticPool.ts @@ -5,7 +5,7 @@ import Utils from '../utils/Utils'; import { WorkerData } from '../types/Worker'; import Wrk from './Wrk'; -export default class WorkerStaticPool extends Wrk { +export default class WorkerStaticPool extends Wrk { private pool: StaticPool; /** @@ -39,7 +39,7 @@ export default class WorkerStaticPool extends Wrk { * @return {Promise} * @public */ - public async addElement(elementData: WorkerData): Promise { + public async addElement(elementData: T): Promise { await this.pool.execute(elementData); // Start worker sequentially to optimize memory at startup await Utils.sleep(Constants.START_WORKER_DELAY); -- 2.34.1