refactor: sensible defaults for worker choice strategy policy
[poolifier.git] / src / worker / cluster-worker.ts
index b22c50fe4160a17ac83b1a525df8090ac1ae9538..35899e794f5b373aa5bca3ec5b3dbe2d1f5cd4c3 100644 (file)
@@ -43,10 +43,21 @@ export class ClusterWorker<
 
   /** @inheritDoc */
   protected handleReadyMessage (message: MessageValue<Data>): void {
-    if (message.workerId === this.id && message.ready != null) {
-      this.getMainWorker()?.on('message', this.messageListener.bind(this))
-      this.sendTaskFunctionsListToMainWorker()
-      this.sendToMainWorker({ ready: true, workerId: this.id })
+    if (message.workerId === this.id && message.ready === false) {
+      try {
+        this.getMainWorker()?.on('message', this.messageListener.bind(this))
+        this.sendToMainWorker({
+          ready: true,
+          taskFunctions: this.listTaskFunctions(),
+          workerId: this.id
+        })
+      } catch {
+        this.sendToMainWorker({
+          ready: false,
+          taskFunctions: this.listTaskFunctions(),
+          workerId: this.id
+        })
+      }
     }
   }