X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fworker%2Fcluster-worker.ts;h=4c1e118789d53f7228e51a5b974b80575985705f;hb=d2c42d447414a85e08936eb45f115a9170e7a6e6;hp=13735b1d697c076c547981e9d5aad8bd22633f84;hpb=6677a3d36e9e7241c54db7cd69daa40f52fcbcb3;p=poolifier.git diff --git a/src/worker/cluster-worker.ts b/src/worker/cluster-worker.ts index 13735b1d..4c1e1187 100644 --- a/src/worker/cluster-worker.ts +++ b/src/worker/cluster-worker.ts @@ -37,19 +37,27 @@ export class ClusterWorker< super( 'worker-cluster-pool:poolifier', cluster.isPrimary, - taskFunctions, cluster.worker as Worker, + taskFunctions, opts ) } /** @inheritDoc */ - protected sendToMainWorker (message: MessageValue): void { - this.getMainWorker().send(message) + 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 }) + } } /** @inheritDoc */ - protected handleError (e: Error | string): string { - return e instanceof Error ? e.message : e + protected get id (): number { + return this.getMainWorker().id + } + + /** @inheritDoc */ + protected sendToMainWorker (message: MessageValue): void { + this.getMainWorker().send(message) } }