X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2Fcluster-worker.ts;h=c43e7f75a7586d2b2a9fa6633eea7da6e44697bf;hb=e677f6c55e0bb599d8e589a937a928229ecd6fea;hp=efc17acf0b9205f05ff621e399b448af2cfbbb47;hpb=e102732c0e3966b81834b2c0bdd087eb051162ad;p=poolifier.git diff --git a/src/worker/cluster-worker.ts b/src/worker/cluster-worker.ts index efc17acf..c43e7f75 100644 --- a/src/worker/cluster-worker.ts +++ b/src/worker/cluster-worker.ts @@ -1,4 +1,4 @@ -import cluster from 'node:cluster' +import cluster, { type Worker } from 'node:cluster' import type { MessageValue } from '../utility-types' import { AbstractWorker } from './abstract-worker' import type { WorkerOptions } from './worker-options' @@ -21,7 +21,7 @@ import type { TaskFunctions, WorkerFunction } from './worker-functions' export class ClusterWorker< Data = unknown, Response = unknown -> extends AbstractWorker { +> extends AbstractWorker { /** * Constructs a new poolifier cluster worker. * @@ -38,22 +38,18 @@ export class ClusterWorker< 'worker-cluster-pool:poolifier', cluster.isPrimary, taskFunctions, - process, + cluster.worker as Worker, opts ) } /** @inheritDoc */ - protected sendToMainWorker (message: MessageValue): void { - const mainWorker = this.getMainWorker() - if (mainWorker.send == null) { - throw new Error('Main worker does not support IPC communication') - } - mainWorker.send(message) + protected get id (): number { + return this.getMainWorker().id } /** @inheritDoc */ - protected handleError (e: Error | string): string { - return e instanceof Error ? e.message : e + protected sendToMainWorker (message: MessageValue): void { + this.getMainWorker().send(message) } }