From: Jérôme Benoit Date: Sat, 3 Jun 2023 12:11:53 +0000 (+0200) Subject: refactor: cleanup worker set code X-Git-Tag: v1.2.16~16 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=b0dee77873629ef36e472deb978a0a0ead3fabca;p=e-mobility-charging-stations-simulator.git refactor: cleanup worker set code Signed-off-by: Jérôme Benoit --- diff --git a/src/worker/WorkerSet.ts b/src/worker/WorkerSet.ts index b16b9542..68160958 100644 --- a/src/worker/WorkerSet.ts +++ b/src/worker/WorkerSet.ts @@ -50,6 +50,21 @@ export class WorkerSet extends WorkerAbstract { return this.workerOptions.elementsPerWorker; } + /** @inheritDoc */ + public async start(): Promise { + this.addWorkerSetElement(); + // Add worker set element sequentially to optimize memory at startup + this.workerOptions.workerStartDelay > 0 && (await sleep(this.workerOptions.workerStartDelay)); + } + + /** @inheritDoc */ + public async stop(): Promise { + for (const workerSetElement of this.workerSet) { + await workerSetElement.worker.terminate(); + } + this.workerSet.clear(); + } + /** @inheritDoc */ public async addElement(elementData: WorkerData): Promise { if (!this.workerSet) { @@ -67,21 +82,6 @@ export class WorkerSet extends WorkerAbstract { } } - /** @inheritDoc */ - public async start(): Promise { - this.addWorkerSetElement(); - // Add worker set element sequentially to optimize memory at startup - this.workerOptions.workerStartDelay > 0 && (await sleep(this.workerOptions.workerStartDelay)); - } - - /** @inheritDoc */ - public async stop(): Promise { - for (const workerSetElement of this.workerSet) { - await workerSetElement.worker.terminate(); - } - this.workerSet.clear(); - } - /** * Add a new `WorkerSetElement`. */