build(deps-dev): bump @rollup/plugin-typescript
[poolifier.git] / src / worker / cluster-worker.ts
index b22c50fe4160a17ac83b1a525df8090ac1ae9538..26964aa489f83fff90f8e4306c3dc1bbafc36f23 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
+        })
+      }
     }
   }