X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fcluster%2Ffixed.ts;h=c60266e3d72b623fb9225dcc20882c064d29438c;hb=efc4d37dd21d0c80e5fa2d58009e6298eefe5d48;hp=d6481be720914c2af14c56bf0182030aa0a456da;hpb=ab3bb4a4fd6b09465fb97ec4f412e57448f94306;p=poolifier.git diff --git a/src/pools/cluster/fixed.ts b/src/pools/cluster/fixed.ts index d6481be7..c60266e3 100644 --- a/src/pools/cluster/fixed.ts +++ b/src/pools/cluster/fixed.ts @@ -1,8 +1,13 @@ import cluster, { type Worker } from 'node:cluster' -import type { MessageValue } from '../../utility-types' -import { AbstractPool } from '../abstract-pool' -import { type PoolOptions, type PoolType, PoolTypes } from '../pool' -import { type WorkerType, WorkerTypes } from '../worker' +import type { MessageValue } from '../../utility-types.js' +import { AbstractPool } from '../abstract-pool.js' +import { type PoolOptions, type PoolType, PoolTypes } from '../pool.js' +import { type WorkerType, WorkerTypes } from '../worker.js' + +/** + * Options for a poolifier cluster pool. + */ +export type ClusterPoolOptions = PoolOptions /** * A cluster pool with a fixed number of workers. @@ -26,7 +31,7 @@ export class FixedClusterPool< public constructor ( numberOfWorkers: number, filePath: string, - opts: PoolOptions = {}, + opts: ClusterPoolOptions = {}, maximumNumberOfWorkers?: number ) { super(numberOfWorkers, filePath, opts, maximumNumberOfWorkers) @@ -49,8 +54,8 @@ export class FixedClusterPool< ): void { this.workerNodes[workerNodeKey].worker.send({ ...message, - workerId: this.getWorkerInfo(workerNodeKey).id as number - }) + workerId: this.getWorkerInfo(workerNodeKey)?.id + } satisfies MessageValue) } /** @inheritDoc */ @@ -84,6 +89,16 @@ export class FixedClusterPool< this.workerNodes[workerNodeKey].worker.off('message', listener) } + /** @inheritDoc */ + protected shallCreateDynamicWorker (): boolean { + return false + } + + /** @inheritDoc */ + protected checkAndEmitDynamicWorkerCreationEvents (): void { + /* noop */ + } + /** @inheritDoc */ protected get type (): PoolType { return PoolTypes.fixed