Extract selection strategies to classes (#176)
[poolifier.git] / src / pools / cluster / dynamic.ts
CommitLineData
c97c7edb 1import type { ClusterPoolOptions } from './fixed'
325f50bc 2import { FixedClusterPool } from './fixed'
f045358d 3
4ade5f1f 4/**
729c563d 5 * A cluster pool with a dynamic number of workers, but a guaranteed minimum number of workers.
4ade5f1f 6 *
729c563d
S
7 * This cluster pool creates new workers when the others are busy, up to the maximum number of workers.
8 * When the maximum number of workers is reached, an event is emitted. If you want to listen to this event, use the pool's `emitter`.
9 *
deb85c12
JB
10 * @template Data Type of data sent to the worker. This can only be serializable data.
11 * @template Response Type of response of execution. This can only be serializable data.
4ade5f1f 12 *
325f50bc
S
13 * @author [Christopher Quadflieg](https://github.com/Shinigami92)
14 * @since 2.0.0
4ade5f1f 15 */
325f50bc 16export class DynamicClusterPool<
deb85c12
JB
17 Data = unknown,
18 Response = unknown
325f50bc 19> extends FixedClusterPool<Data, Response> {
4ade5f1f 20 /**
729c563d
S
21 * Constructs a new poolifier dynamic cluster pool.
22 *
23 * @param min Minimum number of workers which are always active.
24 * @param max Maximum number of workers that can be created by this pool.
31b90205
JB
25 * @param filePath Path to an implementation of a `ClusterWorker` file, which can be relative or absolute.
26 * @param opts Options for this dynamic cluster pool. Default: `{ maxTasks: 1000 }`
4ade5f1f
S
27 */
28 public constructor (
c97c7edb 29 min: number,
4ade5f1f 30 public readonly max: number,
31b90205 31 filePath: string,
c97c7edb 32 opts: ClusterPoolOptions = { maxTasks: 1000 }
4ade5f1f 33 ) {
31b90205 34 super(min, filePath, opts)
4ade5f1f
S
35 }
36
a35560ba
S
37 /** @inheritdoc */
38 public isDynamic (): boolean {
39 return true
4ade5f1f
S
40 }
41}