X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2FWorkerFixedPool.ts;h=96060854743112a438dc408dcc8285842e1bbd19;hb=db0fc072c4f0b42370e213dcc82f75ab3a4fbed8;hp=4eafa1d59933395ee0fb5f2c2dddc9f5404aeb00;hpb=da47bc294fb5e439e96faaf9441ba0cd23e64f9c;p=e-mobility-charging-stations-simulator.git diff --git a/src/worker/WorkerFixedPool.ts b/src/worker/WorkerFixedPool.ts index 4eafa1d5..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 @@ -41,8 +44,8 @@ export class WorkerFixedPool extends WorkerAbstract { } /** @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.elementAddDelay! > 0 && // eslint-disable-next-line @typescript-eslint/no-non-null-assertion (await sleep(randomizeDelay(this.workerOptions.elementAddDelay!))) + return response } }