X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fcluster%2Ffixed.ts;h=10ee92c57876663d07ae96ecdcde036013395126;hb=cac70359b46b8437dd8d23ef6176c6cdfd187c0c;hp=b8a73e4b0562fff6fbca6f48cab4b582c3c5a562;hpb=fc3e65861bc1939ae047ee1e8e91a1ce577035f4;p=poolifier.git diff --git a/src/pools/cluster/fixed.ts b/src/pools/cluster/fixed.ts index b8a73e4b..10ee92c5 100644 --- a/src/pools/cluster/fixed.ts +++ b/src/pools/cluster/fixed.ts @@ -3,7 +3,7 @@ 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 { PoolType } from '../pool' /** * Options for a poolifier cluster pool. @@ -32,7 +32,7 @@ export interface ClusterPoolOptions extends PoolOptions { * This pool selects the workers in a round robin fashion. * * @typeParam Data - Type of data sent to the worker. This can only be serializable data. - * @typeParam Response - Type of response of execution. 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 */ @@ -55,53 +55,63 @@ export class FixedClusterPool< super(numberOfWorkers, filePath, opts) } - /** {@inheritDoc} */ + /** @inheritDoc */ protected setupHook (): void { cluster.setupPrimary({ ...this.opts.settings, exec: this.filePath }) } - /** {@inheritDoc} */ + /** @inheritDoc */ protected isMain (): boolean { return cluster.isPrimary } - /** {@inheritDoc} */ - public destroyWorker (worker: Worker): void { + /** @inheritDoc */ + protected destroyWorker (worker: Worker): void { this.sendToWorker(worker, { kill: 1 }) worker.kill() } - /** {@inheritDoc} */ + /** @inheritDoc */ protected sendToWorker (worker: Worker, message: MessageValue): void { worker.send(message) } - /** {@inheritDoc} */ - public registerWorkerMessageListener( + /** @inheritDoc */ + protected registerWorkerMessageListener( worker: Worker, listener: (message: MessageValue) => void ): void { worker.on('message', listener) } - /** {@inheritDoc} */ + /** @inheritDoc */ protected createWorker (): Worker { return cluster.fork(this.opts.env) } - /** {@inheritDoc} */ + /** @inheritDoc */ protected afterWorkerSetup (worker: Worker): void { // Listen to worker messages. this.registerWorkerMessageListener(worker, super.workerListener()) } - /** {@inheritDoc} */ + /** @inheritDoc */ public get type (): PoolType { return PoolType.FIXED } - /** {@inheritDoc} */ - public get busy (): boolean { - return this.internalGetBusyStatus() + /** @inheritDoc */ + public get size (): number { + return this.numberOfWorkers + } + + /** @inheritDoc */ + protected get full (): boolean { + return this.workerNodes.length === this.numberOfWorkers + } + + /** @inheritDoc */ + protected get busy (): boolean { + return this.internalBusy() } }