test: improve worker code coverage
[poolifier.git] / src / worker / cluster-worker.ts
index 0ccc0013e9d0314425919bc86c3ea51c8da8e29d..26964aa489f83fff90f8e4306c3dc1bbafc36f23 100644 (file)
@@ -43,9 +43,21 @@ export class ClusterWorker<
 
   /** @inheritDoc */
   protected handleReadyMessage (message: MessageValue<Data>): void {
-    if (!this.isMain && message.workerId === this.id && message.ready != null) {
-      this.getMainWorker()?.on('message', this.messageListener.bind(this))
-      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
+        })
+      }
     }
   }