X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fcluster%2Fdynamic.ts;h=9f9abb01ddaa5f3015ef4a08bd2ee046dc9312c9;hb=f06e48d8e14dcfe3277bd16b1bd2463136af13e6;hp=0a2d0f3879fc6ab44129608fec6d9c6624cd4c1a;hpb=5a94e4b950eaf2234e07f87261ddea1482e839c6;p=poolifier.git diff --git a/src/pools/cluster/dynamic.ts b/src/pools/cluster/dynamic.ts index 0a2d0f38..9f9abb01 100644 --- a/src/pools/cluster/dynamic.ts +++ b/src/pools/cluster/dynamic.ts @@ -6,7 +6,7 @@ import { FixedClusterPool } from './fixed' * A cluster pool with a dynamic number of workers, but a guaranteed minimum number of workers. * * This cluster pool creates new workers when the others are busy, up to the maximum number of workers. - * 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`. + * 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`. * * @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. @@ -27,20 +27,25 @@ export class DynamicClusterPool< */ public constructor ( min: number, - protected readonly max: number, + public readonly max: number, filePath: string, opts: ClusterPoolOptions = {} ) { super(min, filePath, opts) } - /** {@inheritDoc} */ + /** @inheritDoc */ public get type (): PoolType { return PoolType.DYNAMIC } - /** {@inheritDoc} */ + /** @inheritDoc */ + public get full (): boolean { + return this.workerNodes.length === this.max + } + + /** @inheritDoc */ public get busy (): boolean { - return this.workers.size === this.max + return this.full && this.findFreeWorkerNodeKey() === -1 } }