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.
/**
* A cluster pool with a fixed number of workers.
- *
* @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
* @typeParam Response - Type of execution response. This can only be structured-cloneable data.
* @author [Christopher Quadflieg](https://github.com/Shinigami92)
> extends AbstractPool<Worker, Data, Response> {
/**
* 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 maximumNumberOfWorkers - The maximum number of workers for this pool.
*/
public constructor (
numberOfWorkers: number,
workerNodeKey: number,
message: MessageValue<Data>
): void {
- this.workerNodes[workerNodeKey].worker.send({
+ this.workerNodes[workerNodeKey]?.worker.send({
...message,
- workerId: this.getWorkerInfo(workerNodeKey).id as number
- })
+ workerId: this.getWorkerInfo(workerNodeKey)?.id,
+ } satisfies MessageValue<Data>)
}
/** @inheritDoc */
protected sendStartupMessageToWorker (workerNodeKey: number): void {
this.sendToWorker(workerNodeKey, {
- ready: false
+ ready: false,
})
}
return false
}
+ /** @inheritDoc */
+ protected checkAndEmitDynamicWorkerCreationEvents (): void {
+ /* noop */
+ }
+
/** @inheritDoc */
protected get type (): PoolType {
return PoolTypes.fixed