X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2Fcluster-worker.ts;h=b22c50fe4160a17ac83b1a525df8090ac1ae9538;hb=bb379737d9bdc595e5265c63c327260b9d15a201;hp=0e3bccd3a7c1dad88019f582e9d1cfe97be663cf;hpb=6c0c538c652e072ffa0516bb2826c39b58b9592f;p=poolifier.git diff --git a/src/worker/cluster-worker.ts b/src/worker/cluster-worker.ts index 0e3bccd3..b22c50fe 100644 --- a/src/worker/cluster-worker.ts +++ b/src/worker/cluster-worker.ts @@ -2,7 +2,7 @@ import cluster, { type Worker } from 'node:cluster' import type { MessageValue } from '../utility-types' import { AbstractWorker } from './abstract-worker' import type { WorkerOptions } from './worker-options' -import type { TaskFunctions, WorkerFunction } from './worker-functions' +import type { TaskFunction, TaskFunctions } from './task-functions' /** * A cluster worker used by a poolifier `ClusterPool`. @@ -29,9 +29,7 @@ export class ClusterWorker< * @param opts - Options for the worker. */ public constructor ( - taskFunctions: - | WorkerFunction - | TaskFunctions, + taskFunctions: TaskFunction | TaskFunctions, opts: WorkerOptions = {} ) { super( @@ -41,14 +39,13 @@ export class ClusterWorker< taskFunctions, opts ) - if (!this.isMain) { - this.getMainWorker()?.on('message', this.messageListener.bind(this)) - } } /** @inheritDoc */ protected handleReadyMessage (message: MessageValue): void { - if (!this.isMain && message.workerId === this.id && message.ready != null) { + if (message.workerId === this.id && message.ready != null) { + this.getMainWorker()?.on('message', this.messageListener.bind(this)) + this.sendTaskFunctionsListToMainWorker() this.sendToMainWorker({ ready: true, workerId: this.id }) } }