X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fcluster%2Ffixed.ts;h=b522947f25cb6f9497c7935fdcd131d1747e8b34;hb=15db9ada70dc79acc82b8efa7888c666f24853b4;hp=6246320e3072d18371646d431692abda06b85ea1;hpb=a35560bac09e829e1e19f88f8fd1d71a64c9d50b;p=poolifier.git diff --git a/src/pools/cluster/fixed.ts b/src/pools/cluster/fixed.ts index 6246320e..b522947f 100644 --- a/src/pools/cluster/fixed.ts +++ b/src/pools/cluster/fixed.ts @@ -2,6 +2,7 @@ import { fork, isMaster, setupMaster, Worker } from 'cluster' import type { MessageValue } from '../../utility-types' import type { PoolOptions } from '../abstract-pool' import { AbstractPool } from '../abstract-pool' +import { PoolType } from '../pool-internal' /** * Options for a poolifier cluster pool. @@ -38,12 +39,12 @@ export class FixedClusterPool< * * @param numberOfWorkers Number of workers for this pool. * @param filePath Path to an implementation of a `ClusterWorker` file, which can be relative or absolute. - * @param opts Options for this fixed cluster pool. Default: `{ maxTasks: 1000 }` + * @param opts Options for this fixed cluster pool. Default: `{}` */ public constructor ( numberOfWorkers: number, filePath: string, - public readonly opts: ClusterPoolOptions = { maxTasks: 1000 } + public readonly opts: ClusterPoolOptions = {} ) { super(numberOfWorkers, filePath, opts) } @@ -76,20 +77,22 @@ export class FixedClusterPool< worker.on('message', listener) } - protected unregisterWorkerMessageListener ( - worker: Worker, - listener: (message: MessageValue) => void - ): void { - worker.removeListener('message', listener) - } - protected createWorker (): Worker { return fork(this.opts.env) } protected afterWorkerSetup (worker: Worker): void { - // We will attach a listener for every task, - // when task is completed the listener will be removed but to avoid warnings we are increasing the max listeners size - worker.setMaxListeners(this.opts.maxTasks ?? 1000) + // Listen worker messages. + this.registerWorkerMessageListener(worker, super.workerListener()) + } + + /** @inheritdoc */ + public get type (): PoolType { + return PoolType.FIXED + } + + /** @inheritdoc */ + public get busy (): boolean { + return this.internalGetBusyStatus() } }