fix: ensure the number of worker choice retries is enough for WRR
[poolifier.git] / src / worker / thread-worker.ts
index 7b92caf67201795797f6e3e06fff4fc593f4ee94..bc143a1f914b7e7dba14b395ac456be40c59ed80 100644 (file)
@@ -30,7 +30,8 @@ export class ThreadWorker<
   /**
    * Message port used to communicate with the main worker.
    */
-  private port!: MessagePort
+  private port?: MessagePort
+
   /**
    * Constructs a new poolifier thread worker.
    *
@@ -41,13 +42,7 @@ export class ThreadWorker<
     taskFunctions: TaskFunction<Data, Response> | TaskFunctions<Data, Response>,
     opts: WorkerOptions = {}
   ) {
-    super(
-      'worker-thread-pool:poolifier',
-      isMainThread,
-      parentPort as MessagePort,
-      taskFunctions,
-      opts
-    )
+    super(isMainThread, parentPort as MessagePort, taskFunctions, opts)
   }
 
   /** @inheritDoc */
@@ -86,11 +81,16 @@ export class ThreadWorker<
   }
 
   /** @inheritDoc */
-  protected sendToMainWorker (message: MessageValue<Response>): void {
-    this.port.postMessage({ ...message, workerId: this.id })
+  protected readonly sendToMainWorker = (
+    message: MessageValue<Response>
+  ): void => {
+    this.port?.postMessage({ ...message, workerId: this.id })
   }
 
-  /** @inheritDoc */
+  /**
+   * @inheritDoc
+   * @override
+   */
   protected handleError (error: Error | string): string {
     return error as string
   }