X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fcluster%2Ffixed.ts;h=a0c6b16f6ed7b5a16e38c30c75c62302cd54b9c7;hb=f8350486e75b15ed17249cda3d0a55ee807a6a9f;hp=a98cd647eeb59d925f7bd8c3ed6685abf80c1eaf;hpb=4ce0c32173afaa80991976d39dc741e49d0c62bc;p=poolifier.git diff --git a/src/pools/cluster/fixed.ts b/src/pools/cluster/fixed.ts index a98cd647..a0c6b16f 100644 --- a/src/pools/cluster/fixed.ts +++ b/src/pools/cluster/fixed.ts @@ -1,9 +1,8 @@ -import type { ClusterSettings, Worker } from 'cluster' -import cluster from 'cluster' +import type { ClusterSettings, Worker } from 'node:cluster' +import cluster from 'node:cluster' import type { MessageValue } from '../../utility-types' import { AbstractPool } from '../abstract-pool' -import type { PoolOptions } from '../pool' -import { PoolType } from '../pool-internal' +import { type PoolOptions, type PoolType, PoolTypes } from '../pool' /** * Options for a poolifier cluster pool. @@ -31,8 +30,8 @@ export interface ClusterPoolOptions extends PoolOptions { * * This pool selects the workers in a round robin fashion. * - * @template DataType of data sent to the worker. This can only be serializable data. - * @template ResponseType of response of execution. This can only be serializable data. + * @typeParam Data - Type of data sent to the worker. This can only be serializable data. + * @typeParam Response - Type of execution response. This can only be serializable data. * @author [Christopher Quadflieg](https://github.com/Shinigami92) * @since 2.0.0 */ @@ -43,9 +42,9 @@ export class FixedClusterPool< /** * Constructs a new poolifier fixed cluster pool. * - * @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. + * @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. */ public constructor ( numberOfWorkers: number, @@ -66,7 +65,7 @@ export class FixedClusterPool< } /** @inheritDoc */ - public destroyWorker (worker: Worker): void { + protected destroyWorker (worker: Worker): void { this.sendToWorker(worker, { kill: 1 }) worker.kill() } @@ -77,7 +76,7 @@ export class FixedClusterPool< } /** @inheritDoc */ - public registerWorkerMessageListener ( + protected registerWorkerMessageListener( worker: Worker, listener: (message: MessageValue) => void ): void { @@ -91,17 +90,32 @@ export class FixedClusterPool< /** @inheritDoc */ protected afterWorkerSetup (worker: Worker): void { - // Listen worker messages. + // Listen to worker messages. this.registerWorkerMessageListener(worker, super.workerListener()) } /** @inheritDoc */ public get type (): PoolType { - return PoolType.FIXED + return PoolTypes.fixed } /** @inheritDoc */ - public get busy (): boolean { - return this.internalGetBusyStatus() + protected get minSize (): number { + return this.numberOfWorkers + } + + /** @inheritDoc */ + protected get maxSize (): number { + return this.numberOfWorkers + } + + /** @inheritDoc */ + protected get full (): boolean { + return this.workerNodes.length >= this.numberOfWorkers + } + + /** @inheritDoc */ + protected get busy (): boolean { + return this.internalBusy() } }