X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2FWorkerFixedPool.ts;h=96060854743112a438dc408dcc8285842e1bbd19;hb=8fb8f42ace8b9295865adebaeb7845e064c05e71;hp=a2a0e759d7004f65658d89ff60b684b5d53dad99;hpb=66a7748ddeda8c94d7562a1ce58d440319654a4c;p=e-mobility-charging-stations-simulator.git diff --git a/src/worker/WorkerFixedPool.ts b/src/worker/WorkerFixedPool.ts index a2a0e759..96060854 100644 --- a/src/worker/WorkerFixedPool.ts +++ b/src/worker/WorkerFixedPool.ts @@ -6,8 +6,11 @@ import { WorkerAbstract } from './WorkerAbstract.js' import type { WorkerData, WorkerOptions } from './WorkerTypes.js' import { randomizeDelay, sleep } from './WorkerUtils.js' -export class WorkerFixedPool extends WorkerAbstract { - private readonly pool: FixedThreadPool +export class WorkerFixedPool extends WorkerAbstract< +D, +R +> { + private readonly pool: FixedThreadPool /** * Creates a new `WorkerFixedPool`. @@ -17,7 +20,7 @@ export class WorkerFixedPool extends WorkerAbstract { */ constructor (workerScript: string, workerOptions: WorkerOptions) { super(workerScript, workerOptions) - this.pool = new FixedThreadPool( + this.pool = new FixedThreadPool( this.workerOptions.poolMaxSize, this.workerScript, this.workerOptions.poolOptions @@ -37,12 +40,12 @@ export class WorkerFixedPool extends WorkerAbstract { } get emitter (): EventEmitterAsyncResource | undefined { - return this.pool?.emitter + return this.pool.emitter } /** @inheritDoc */ - public async start (): Promise { - // This is intentional + public start (): void { + this.pool.start() } /** @inheritDoc */ @@ -51,12 +54,13 @@ export class WorkerFixedPool extends WorkerAbstract { } /** @inheritDoc */ - public async addElement (elementData: WorkerData): Promise { - await this.pool.execute(elementData) + public async addElement (elementData: D): Promise { + const response = await this.pool.execute(elementData) // Start element sequentially to optimize memory at startup // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - this.workerOptions.elementStartDelay! > 0 && + this.workerOptions.elementAddDelay! > 0 && // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - (await sleep(randomizeDelay(this.workerOptions.elementStartDelay!))) + (await sleep(randomizeDelay(this.workerOptions.elementAddDelay!))) + return response } }