taskFunctions: TaskFunction<Data, Response> | TaskFunctions<Data, Response>,
opts: WorkerOptions = {}
) {
- super(
- 'worker-cluster-pool:poolifier',
- cluster.isPrimary,
- cluster.worker as Worker,
- taskFunctions,
- opts
- )
+ super(cluster.isPrimary, cluster.worker as Worker, taskFunctions, opts)
}
/** @inheritDoc */
protected handleReadyMessage (message: MessageValue<Data>): void {
if (message.workerId === this.id && message.ready === false) {
try {
- this.getMainWorker()?.on('message', this.messageListener.bind(this))
- this.sendTaskFunctionsListToMainWorker()
- this.sendToMainWorker({ ready: true, workerId: this.id })
+ this.getMainWorker().on('message', this.messageListener.bind(this))
+ this.sendToMainWorker({
+ ready: true,
+ taskFunctionNames: this.listTaskFunctionNames()
+ })
} catch {
- this.sendToMainWorker({ ready: false, workerId: this.id })
+ this.sendToMainWorker({
+ ready: false,
+ taskFunctionNames: this.listTaskFunctionNames()
+ })
}
}
}
}
/** @inheritDoc */
- protected sendToMainWorker (message: MessageValue<Response>): void {
- this.getMainWorker().send(message)
+ protected readonly sendToMainWorker = (
+ message: MessageValue<Response>
+ ): void => {
+ this.getMainWorker().send({ ...message, workerId: this.id })
}
}