export { FixedClusterPool } from './pools/cluster/fixed'
export type { ClusterPoolOptions } from './pools/cluster/fixed'
export type { AbstractPool } from './pools/abstract-pool'
-export { PoolEvents, PoolTypes } from './pools/pool'
+export { PoolEvents, PoolTypes, WorkerTypes } from './pools/pool'
export type {
IPool,
PoolEmitter,
PoolInfo,
PoolOptions,
PoolType,
- TasksQueueOptions
+ TasksQueueOptions,
+ WorkerType
} from './pools/pool'
export type {
ErrorHandler,
type PoolOptions,
type PoolType,
PoolTypes,
- type TasksQueueOptions
+ type TasksQueueOptions,
+ type WorkerType
} from './pool'
import type { IWorker, Task, TasksUsage, WorkerNode } from './worker'
import {
public get info (): PoolInfo {
return {
type: this.type,
+ worker: this.worker,
minSize: this.minSize,
maxSize: this.maxSize,
workerNodes: this.workerNodes.length,
}
}
+ /**
+ * Gets the worker type.
+ */
+ protected abstract get worker (): WorkerType
+
/**
* Pool minimum size.
*/
import cluster from 'node:cluster'
import type { MessageValue } from '../../utility-types'
import { AbstractPool } from '../abstract-pool'
-import { type PoolOptions, type PoolType, PoolTypes } from '../pool'
+import {
+ type PoolOptions,
+ type PoolType,
+ PoolTypes,
+ type WorkerType,
+ WorkerTypes
+} from '../pool'
/**
* Options for a poolifier cluster pool.
return PoolTypes.fixed
}
+ /** @inheritDoc */
+ protected get worker (): WorkerType {
+ return WorkerTypes.cluster
+ }
+
/** @inheritDoc */
protected get minSize (): number {
return this.numberOfWorkers
*/
export type PoolType = keyof typeof PoolTypes
+/**
+ * Enumeration of worker types.
+ */
+export const WorkerTypes = Object.freeze({
+ cluster: 'cluster',
+ thread: 'thread'
+} as const)
+
+/**
+ * Worker type.
+ */
+export type WorkerType = keyof typeof WorkerTypes
+
/**
* Pool events emitter.
*/
*/
export interface PoolInfo {
type: PoolType
+ worker: WorkerType
minSize: number
maxSize: number
workerNodes: number
} from 'node:worker_threads'
import type { Draft, MessageValue } from '../../utility-types'
import { AbstractPool } from '../abstract-pool'
-import { type PoolOptions, type PoolType, PoolTypes } from '../pool'
+import {
+ type PoolOptions,
+ type PoolType,
+ PoolTypes,
+ type WorkerType,
+ WorkerTypes
+} from '../pool'
/**
* A thread worker with message channels for communication between main thread and thread worker.
return PoolTypes.fixed
}
+ /** @inheritDoc */
+ protected get worker (): WorkerType {
+ return WorkerTypes.thread
+ }
+
/** @inheritDoc */
protected get minSize (): number {
return this.numberOfWorkers
FixedThreadPool,
PoolEvents,
WorkerChoiceStrategies,
- PoolTypes
+ PoolTypes,
+ WorkerTypes
} = require('../../../lib')
const { CircularArray } = require('../../../lib/circular-array')
const { Queue } = require('../../../lib/queue')
)
expect(pool.info).toStrictEqual({
type: PoolTypes.fixed,
+ worker: WorkerTypes.thread,
minSize: numberOfWorkers,
maxSize: numberOfWorkers,
workerNodes: numberOfWorkers,
)
expect(pool.info).toStrictEqual({
type: PoolTypes.dynamic,
+ worker: WorkerTypes.cluster,
minSize: numberOfWorkers,
maxSize: numberOfWorkers * 2,
workerNodes: numberOfWorkers,