docs: refine CONTRIBUTING.md
[poolifier.git] / src / worker / cluster-worker.ts
index 16dddd2969bd50193c4fb43e762d607f08f4ca08..4c1e118789d53f7228e51a5b974b80575985705f 100644 (file)
@@ -37,12 +37,17 @@ export class ClusterWorker<
     super(
       'worker-cluster-pool:poolifier',
       cluster.isPrimary,
-      taskFunctions,
       cluster.worker as Worker,
+      taskFunctions,
       opts
     )
-    if (!this.isMain) {
-      this.sendToMainWorker({ workerId: this.id, started: true })
+  }
+
+  /** @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 })
     }
   }
 
@@ -53,12 +58,6 @@ export class ClusterWorker<
 
   /** @inheritDoc */
   protected sendToMainWorker (message: MessageValue<Response>): void {
-    console.log('sending message to main worker(cluster)', message)
     this.getMainWorker().send(message)
   }
-
-  /** @inheritDoc */
-  protected handleError (e: Error | string): string {
-    return e instanceof Error ? e.message : e
-  }
 }