X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2Fcluster-worker.ts;h=4c1e118789d53f7228e51a5b974b80575985705f;hb=d2c42d447414a85e08936eb45f115a9170e7a6e6;hp=16dddd2969bd50193c4fb43e762d607f08f4ca08;hpb=76aa2b0f39bd376383f2fdc79046328693719590;p=poolifier.git diff --git a/src/worker/cluster-worker.ts b/src/worker/cluster-worker.ts index 16dddd29..4c1e1187 100644 --- a/src/worker/cluster-worker.ts +++ b/src/worker/cluster-worker.ts @@ -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): 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): 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 - } }