From dea903a811a58acdf93f11379b347bfd8088e970 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 4 Jun 2023 15:53:23 +0200 Subject: [PATCH] refactor: factor out pool fullness detection MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/pools/abstract-pool.ts | 4 +++- src/pools/cluster/dynamic.ts | 5 ----- src/pools/cluster/fixed.ts | 7 +------ src/pools/thread/dynamic.ts | 5 ----- src/pools/thread/fixed.ts | 5 ----- 5 files changed, 4 insertions(+), 22 deletions(-) diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 5d7e8cd8..43abfda7 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -357,7 +357,9 @@ export abstract class AbstractPool< * * The pool filling boolean status. */ - protected abstract get full (): boolean + protected get full (): boolean { + return this.workerNodes.length >= this.maxSize + } /** * Whether the pool is busy or not. diff --git a/src/pools/cluster/dynamic.ts b/src/pools/cluster/dynamic.ts index eb86ba85..b75b3f80 100644 --- a/src/pools/cluster/dynamic.ts +++ b/src/pools/cluster/dynamic.ts @@ -43,11 +43,6 @@ export class DynamicClusterPool< return this.max } - /** @inheritDoc */ - protected get full (): boolean { - return this.workerNodes.length >= this.max - } - /** @inheritDoc */ protected get busy (): boolean { return this.full && this.internalBusy() diff --git a/src/pools/cluster/fixed.ts b/src/pools/cluster/fixed.ts index 0ca0250c..f22906df 100644 --- a/src/pools/cluster/fixed.ts +++ b/src/pools/cluster/fixed.ts @@ -54,7 +54,7 @@ export class FixedClusterPool< public constructor ( numberOfWorkers: number, filePath: string, - public readonly opts: ClusterPoolOptions = {} + protected readonly opts: ClusterPoolOptions = {} ) { super(numberOfWorkers, filePath, opts) } @@ -119,11 +119,6 @@ export class FixedClusterPool< return this.numberOfWorkers } - /** @inheritDoc */ - protected get full (): boolean { - return this.workerNodes.length >= this.numberOfWorkers - } - /** @inheritDoc */ protected get busy (): boolean { return this.internalBusy() diff --git a/src/pools/thread/dynamic.ts b/src/pools/thread/dynamic.ts index 8cdb0d5c..90889c9b 100644 --- a/src/pools/thread/dynamic.ts +++ b/src/pools/thread/dynamic.ts @@ -43,11 +43,6 @@ export class DynamicThreadPool< return this.max } - /** @inheritDoc */ - protected get full (): boolean { - return this.workerNodes.length >= this.max - } - /** @inheritDoc */ protected get busy (): boolean { return this.full && this.internalBusy() diff --git a/src/pools/thread/fixed.ts b/src/pools/thread/fixed.ts index be1a8baa..f0a49056 100644 --- a/src/pools/thread/fixed.ts +++ b/src/pools/thread/fixed.ts @@ -116,11 +116,6 @@ export class FixedThreadPool< return this.numberOfWorkers } - /** @inheritDoc */ - protected get full (): boolean { - return this.workerNodes.length >= this.numberOfWorkers - } - /** @inheritDoc */ protected get busy (): boolean { return this.internalBusy() -- 2.34.1