refactor: cleanup worker set code
authorJérôme Benoit <jerome.benoit@sap.com>
Sat, 3 Jun 2023 12:11:53 +0000 (14:11 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sat, 3 Jun 2023 12:11:53 +0000 (14:11 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/worker/WorkerSet.ts

index b16b95424ec7d8eca5996e7b05ddf4759ef2df13..681609585de1d388fe59135fb778fcf39fccc384 100644 (file)
@@ -50,6 +50,21 @@ export class WorkerSet extends WorkerAbstract<WorkerData> {
     return this.workerOptions.elementsPerWorker;
   }
 
+  /** @inheritDoc */
+  public async start(): Promise<void> {
+    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<void> {
+    for (const workerSetElement of this.workerSet) {
+      await workerSetElement.worker.terminate();
+    }
+    this.workerSet.clear();
+  }
+
   /** @inheritDoc */
   public async addElement(elementData: WorkerData): Promise<void> {
     if (!this.workerSet) {
@@ -67,21 +82,6 @@ export class WorkerSet extends WorkerAbstract<WorkerData> {
     }
   }
 
-  /** @inheritDoc */
-  public async start(): Promise<void> {
-    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<void> {
-    for (const workerSetElement of this.workerSet) {
-      await workerSetElement.worker.terminate();
-    }
-    this.workerSet.clear();
-  }
-
   /**
    * Add a new `WorkerSetElement`.
    */