78c63aca64d8da1e879c723bd0fd064f46de83ee
1 import { PoolType
} from
'../pool'
2 import type { ClusterPoolOptions
} from
'./fixed'
3 import { FixedClusterPool
} from
'./fixed'
6 * A cluster pool with a dynamic number of workers, but a guaranteed minimum number of workers.
8 * This cluster pool creates new workers when the others are busy, up to the maximum number of workers.
9 * When the maximum number of workers is reached and workers are busy, an event is emitted. If you want to listen to this event, use the pool's `emitter`.
11 * @typeParam Data - Type of data sent to the worker. This can only be serializable data.
12 * @typeParam Response - Type of response of execution. This can only be serializable data.
13 * @author [Christopher Quadflieg](https://github.com/Shinigami92)
16 export class DynamicClusterPool
<
19 > extends FixedClusterPool
<Data
, Response
> {
21 * Constructs a new poolifier dynamic cluster pool.
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.
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.
30 public readonly max
: number,
32 opts
: ClusterPoolOptions
= {}
34 super(min
, filePath
, opts
)
38 public get
type (): PoolType
{
39 return PoolType
.DYNAMIC
43 protected get
full (): boolean {
44 return this.workerNodes
.length
=== this.max
48 protected get
busy (): boolean {
49 return this.full
&& this.internalBusy()