refactor: cleanup worker id handling code
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 19 Jul 2023 22:21:32 +0000 (00:21 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 19 Jul 2023 22:21:32 +0000 (00:21 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/pools/cluster/fixed.ts
src/pools/thread/fixed.ts
src/worker/abstract-worker.ts

index d7e3cc4bce0c4291bac5a71df3b9878933f96148..dbf1d470b7e7f36eb12dec0bba28c081fac60786 100644 (file)
@@ -77,7 +77,7 @@ export class FixedClusterPool<
   protected sendStartupMessageToWorker (worker: Worker): void {
     this.sendToWorker(worker, {
       ready: false,
-      workerId: this.getWorkerInfoByWorker(worker).id as number
+      workerId: worker.id
     })
   }
 
index 52868fd7ec4360e62d9ab565995bb4ce532fde02..e3a94b329d4cfcee6f05cd6e2f8ad06e555a6dfc 100644 (file)
@@ -79,7 +79,7 @@ export class FixedThreadPool<
     worker.postMessage(
       {
         ready: false,
-        workerId: this.getWorkerInfoByWorker(worker).id as number,
+        workerId: worker.threadId,
         port: port2
       },
       [port2]
index 36b7d03e379415aa3ec24aa861ae40e12d7f268b..67b4b5ff9e4575ead2d824537fb106d6d0b5ba11 100644 (file)
@@ -284,6 +284,13 @@ export abstract class AbstractWorker<
     }
   }
 
+  /**
+   * Handles the ready message sent by the main worker.
+   *
+   * @param message - The ready message.
+   */
+  protected abstract handleReadyMessage (message: MessageValue<Data>): void
+
   /**
    * Worker message listener.
    *
@@ -310,13 +317,6 @@ export abstract class AbstractWorker<
     }
   }
 
-  /**
-   * Handles the ready message sent by the main worker.
-   *
-   * @param message - The ready message.
-   */
-  protected abstract handleReadyMessage (message: MessageValue<Data>): void
-
   /**
    * Starts the worker check active interval.
    */