fix: wait for worker exit to clean the worker set
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 21 Jul 2023 13:53:55 +0000 (15:53 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 21 Jul 2023 13:53:55 +0000 (15:53 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/worker/WorkerSet.ts

index 2514d7239a24dc01baeb98f22c8a492c0f574260..42109a98567609739d70a4e00c3c10d6e7420d07 100644 (file)
@@ -77,15 +77,15 @@ export class WorkerSet extends WorkerAbstract<WorkerData> {
   /** @inheritDoc */
   public async stop(): Promise<void> {
     for (const workerSetElement of this.workerSet) {
+      const worker = workerSetElement.worker;
       const workerExitPromise = new Promise<void>((resolve) => {
-        workerSetElement.worker.on('exit', () => {
+        worker.on('exit', () => {
           resolve();
         });
       });
-      await workerSetElement.worker.terminate();
+      await worker.terminate();
       await workerExitPromise;
     }
-    this.workerSet.clear();
   }
 
   /** @inheritDoc */