1 import { PoolType
} from
'../pool-internal'
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, an event is emitted. If you want to listen to this event, use the pool's `emitter`.
11 * @template Data Type of data sent to the worker. This can only be serializable data.
12 * @template Response Type of response of execution. This can only be serializable data.
14 * @author [Christopher Quadflieg](https://github.com/Shinigami92)
17 export class DynamicClusterPool
<
20 > extends FixedClusterPool
<Data
, Response
> {
22 * Constructs a new poolifier dynamic cluster pool.
24 * @param min Minimum number of workers which are always active.
25 * @param max Maximum number of workers that can be created by this pool.
26 * @param filePath Path to an implementation of a `ClusterWorker` file, which can be relative or absolute.
27 * @param opts Options for this dynamic cluster pool. Default: `{}`
31 public readonly max
: number,
33 opts
: ClusterPoolOptions
= {}
35 super(min
, filePath
, opts
)
39 public get
type (): PoolType
{
40 return PoolType
.DYNAMIC
44 public get
busy (): boolean {
45 return this.workers
.length
=== this.max