X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2FWorkerFixedPool.ts;h=96060854743112a438dc408dcc8285842e1bbd19;hb=3b09e788c6dab8e5a8b3314e8e69ede16ff82fcc;hp=22290666c17546e1f3c0f461a0cbca39e0841de2;hpb=8ae4dcf159bf29835de7fd1edd7978aa8a3ee76b;p=e-mobility-charging-stations-simulator.git diff --git a/src/worker/WorkerFixedPool.ts b/src/worker/WorkerFixedPool.ts index 22290666..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 @@ -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 } }