X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fcluster%2Ffixed.ts;h=78de7073b615fc10936091aca0cd203165efaac8;hb=a22cdf86c993800ec9ea8ae32ef0d8dbda07ec61;hp=2e89b3232dccbc321907b02a73b583d650ee1661;hpb=ed6dd37f9e137cf659523d9d792f0171eedcb8ed;p=poolifier.git diff --git a/src/pools/cluster/fixed.ts b/src/pools/cluster/fixed.ts index 2e89b323..78de7073 100644 --- a/src/pools/cluster/fixed.ts +++ b/src/pools/cluster/fixed.ts @@ -1,5 +1,5 @@ -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' @@ -55,28 +55,28 @@ 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} */ + /** @inheritDoc */ public destroyWorker (worker: Worker): void { this.sendToWorker(worker, { kill: 1 }) worker.kill() } - /** {@inheritDoc} */ + /** @inheritDoc */ protected sendToWorker (worker: Worker, message: MessageValue): void { worker.send(message) } - /** {@inheritDoc} */ + /** @inheritDoc */ public registerWorkerMessageListener( worker: Worker, listener: (message: MessageValue) => void @@ -84,24 +84,29 @@ export class FixedClusterPool< 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} */ + /** @inheritDoc */ + public get full (): boolean { + return this.workers.length === this.numberOfWorkers + } + + /** @inheritDoc */ public get busy (): boolean { - return this.internalGetBusyStatus() + return this.internalBusy() } }