export { DynamicClusterPool } from './pools/cluster/dynamic'
export { FixedClusterPool } from './pools/cluster/fixed'
export type { ClusterPoolOptions } from './pools/cluster/fixed'
+export type { AbstractPool } from './pools/abstract-pool'
export { PoolEvents } from './pools/pool'
export type {
IPool,
ExitHandler,
IWorker,
MessageHandler,
- OnlineHandler
+ OnlineHandler,
+ WorkerNode
} from './pools/worker'
export { WorkerChoiceStrategies } from './pools/selection-strategies/selection-strategies-types'
export type {
+ IWorkerChoiceStrategy,
WorkerChoiceStrategy,
WorkerChoiceStrategyOptions
} from './pools/selection-strategies/selection-strategies-types'
+export type { WorkerChoiceStrategyContext } from './pools/selection-strategies/worker-choice-strategy-context'
export { DynamicThreadPool } from './pools/thread/dynamic'
export { FixedThreadPool } from './pools/thread/fixed'
export type { ThreadWorkerWithMessageChannel } from './pools/thread/fixed'
+export type { AbstractWorker } from './worker/abstract-worker'
export { ClusterWorker } from './worker/cluster-worker'
export { ThreadWorker } from './worker/thread-worker'
export { KillBehaviors } from './worker/worker-options'
export type { KillBehavior, WorkerOptions } from './worker/worker-options'
+export type { Draft, MessageValue } from './utility-types'
median
} from '../utils'
import { KillBehaviors, isKillBehavior } from '../worker/worker-options'
-import { PoolEvents, type PoolOptions, type TasksQueueOptions } from './pool'
+import {
+ PoolEvents,
+ type IPool,
+ type PoolOptions,
+ type TasksQueueOptions,
+ PoolType
+} from './pool'
import { PoolEmitter } from './pool'
-import type { IPoolInternal } from './pool-internal'
-import { PoolType } from './pool-internal'
import type { IWorker, Task, TasksUsage, WorkerNode } from './worker'
import {
WorkerChoiceStrategies,
Worker extends IWorker,
Data = unknown,
Response = unknown
-> implements IPoolInternal<Worker, Data, Response> {
+> implements IPool<Worker, Data, Response> {
/** @inheritDoc */
public readonly workerNodes: Array<WorkerNode<Worker, Data>> = []
-import { PoolType } from '../pool-internal'
+import { PoolType } from '../pool'
import type { ClusterPoolOptions } from './fixed'
import { FixedClusterPool } from './fixed'
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.
+++ /dev/null
-import type { IPool } from './pool'
-import type { IWorker, WorkerNode } from './worker'
-
-/**
- * Internal pool types.
- *
- * @enum
- */
-export enum PoolType {
- /**
- * Fixed pool type.
- */
- FIXED = 'fixed',
- /**
- * Dynamic pool type.
- */
- DYNAMIC = 'dynamic'
-}
-
-/**
- * Internal contract definition for a poolifier pool.
- *
- * @typeParam Worker - Type of worker which manages this pool.
- * @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.
- */
-export interface IPoolInternal<
- Worker extends IWorker,
- Data = unknown,
- Response = unknown
-> extends IPool<Data, Response> {
- /**
- * Pool worker nodes.
- */
- readonly workerNodes: Array<WorkerNode<Worker, Data>>
-
- /**
- * Pool type.
- *
- * If it is `'dynamic'`, it provides the `max` property.
- */
- readonly type: PoolType
-
- /**
- * Whether the pool is full or not.
- *
- * The pool filling boolean status.
- */
- readonly full: boolean
-
- /**
- * Whether the pool is busy or not.
- *
- * The pool busyness boolean status.
- */
- readonly busy: boolean
-
- /**
- * Finds a free worker node key based on the number of tasks the worker has applied.
- *
- * If a worker is found with `0` running tasks, it is detected as free and its worker node key is returned.
- *
- * If no free worker is found, `-1` is returned.
- *
- * @returns A worker node key if there is one, `-1` otherwise.
- */
- findFreeWorkerNodeKey: () => number
-}
ExitHandler,
IWorker,
MessageHandler,
- OnlineHandler
+ OnlineHandler,
+ WorkerNode
} from './worker'
import type {
WorkerChoiceStrategy,
WorkerChoiceStrategyOptions
} from './selection-strategies/selection-strategies-types'
+/**
+ * Pool types.
+ *
+ * @enum
+ */
+export enum PoolType {
+ /**
+ * Fixed pool type.
+ */
+ FIXED = 'fixed',
+ /**
+ * Dynamic pool type.
+ */
+ DYNAMIC = 'dynamic'
+}
+
/**
* Pool events emitter.
*/
/**
* Contract definition for a poolifier pool.
*
+ * @typeParam Worker - Type of worker which manages this pool.
* @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.
*/
-export interface IPool<Data = unknown, Response = unknown> {
+export interface IPool<
+ Worker extends IWorker,
+ Data = unknown,
+ Response = unknown
+> {
+ /**
+ * Pool type.
+ *
+ * If it is `'dynamic'`, it provides the `max` property.
+ */
+ readonly type: PoolType
+ /**
+ * Pool worker nodes.
+ */
+ readonly workerNodes: Array<WorkerNode<Worker, Data>>
/**
* Emitter on which events can be listened to.
*
* - `'busy'`: Emitted when the pool is busy.
*/
readonly emitter?: PoolEmitter
+ /**
+ * Whether the pool is full or not.
+ *
+ * The pool filling boolean status.
+ */
+ readonly full: boolean
+ /**
+ * Whether the pool is busy or not.
+ *
+ * The pool busyness boolean status.
+ */
+ readonly busy: boolean
+ /**
+ * Finds a free worker node key based on the number of tasks the worker has applied.
+ *
+ * If a worker is found with `0` running tasks, it is detected as free and its worker node key is returned.
+ *
+ * If no free worker is found, `-1` is returned.
+ *
+ * @returns A worker node key if there is one, `-1` otherwise.
+ */
+ findFreeWorkerNodeKey: () => number
/**
* Performs the task specified in the constructor with the data parameter.
*
import { DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS } from '../../utils'
-import type { IPoolInternal } from '../pool-internal'
-import { PoolType } from '../pool-internal'
+import { PoolType, type IPool } from '../pool'
import type { IWorker } from '../worker'
import type {
IWorkerChoiceStrategy,
* @param opts - The worker choice strategy options.
*/
public constructor (
- protected readonly pool: IPoolInternal<Worker, Data, Response>,
+ protected readonly pool: IPool<Worker, Data, Response>,
protected readonly opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS
) {
this.checkOptions(this.opts)
import { cpus } from 'node:os'
-import type { IPoolInternal } from '../pool-internal'
import type { IWorker } from '../worker'
import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
import type {
RequiredStatistics,
WorkerChoiceStrategyOptions
} from './selection-strategies-types'
+import type { IPool } from '../pool'
/**
* Virtual task runtime.
* @param opts - The worker choice strategy options.
*/
public constructor (
- pool: IPoolInternal<Worker, Data, Response>,
+ pool: IPool<Worker, Data, Response>,
opts?: WorkerChoiceStrategyOptions
) {
super(pool, opts)
import { DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS } from '../../utils'
-import type { IPoolInternal } from '../pool-internal'
+import type { IPool } from '../pool'
import type { IWorker } from '../worker'
import { FairShareWorkerChoiceStrategy } from './fair-share-worker-choice-strategy'
import { LessBusyWorkerChoiceStrategy } from './less-busy-worker-choice-strategy'
* @param opts - The worker choice strategy options.
*/
public constructor (
- pool: IPoolInternal<Worker, Data, Response>,
+ pool: IPool<Worker, Data, Response>,
private workerChoiceStrategyType: WorkerChoiceStrategy = WorkerChoiceStrategies.ROUND_ROBIN,
opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS
) {
import type { PoolOptions } from '../pool'
-import { PoolType } from '../pool-internal'
+import { PoolType } from '../pool'
import type { ThreadWorkerWithMessageChannel } from './fixed'
import { FixedThreadPool } from './fixed'
import type { Draft, MessageValue } from '../../utility-types'
import { AbstractPool } from '../abstract-pool'
import type { PoolOptions } from '../pool'
-import { PoolType } from '../pool-internal'
+import { PoolType } from '../pool'
/**
* A thread worker with message channels for communication between main thread and thread worker.