From: Jérôme Benoit Date: Tue, 11 Apr 2023 21:09:12 +0000 (+0200) Subject: docs: enhance documentation X-Git-Tag: v2.4.7~4 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=c319c66bad0611acf6087950a1f8a20f8124167b;p=poolifier.git docs: enhance documentation Signed-off-by: Jérôme Benoit --- diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 1237491b..b95d16b4 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -227,11 +227,19 @@ export abstract class AbstractPool< ) } - /** @inheritDoc */ - public abstract get full (): boolean + /** + * Whether the pool is full or not. + * + * The pool filling boolean status. + */ + protected abstract get full (): boolean - /** @inheritDoc */ - public abstract get busy (): boolean + /** + * Whether the pool is busy or not. + * + * The pool busyness boolean status. + */ + protected abstract get busy (): boolean protected internalBusy (): boolean { return this.findFreeWorkerNodeKey() === -1 diff --git a/src/pools/cluster/dynamic.ts b/src/pools/cluster/dynamic.ts index 92f0068e..78c63aca 100644 --- a/src/pools/cluster/dynamic.ts +++ b/src/pools/cluster/dynamic.ts @@ -40,12 +40,12 @@ export class DynamicClusterPool< } /** @inheritDoc */ - public get full (): boolean { + protected get full (): boolean { return this.workerNodes.length === this.max } /** @inheritDoc */ - public get busy (): boolean { + protected get busy (): boolean { return this.full && this.internalBusy() } } diff --git a/src/pools/cluster/fixed.ts b/src/pools/cluster/fixed.ts index e29c8c0f..81e7b3b7 100644 --- a/src/pools/cluster/fixed.ts +++ b/src/pools/cluster/fixed.ts @@ -77,7 +77,7 @@ export class FixedClusterPool< } /** @inheritDoc */ - public registerWorkerMessageListener( + protected registerWorkerMessageListener( worker: Worker, listener: (message: MessageValue) => void ): void { @@ -101,12 +101,12 @@ export class FixedClusterPool< } /** @inheritDoc */ - public get full (): boolean { + protected get full (): boolean { return this.workerNodes.length === this.numberOfWorkers } /** @inheritDoc */ - public get busy (): boolean { + protected get busy (): boolean { return this.internalBusy() } } diff --git a/src/pools/pool.ts b/src/pools/pool.ts index 92e399ed..17088559 100644 --- a/src/pools/pool.ts +++ b/src/pools/pool.ts @@ -60,6 +60,8 @@ export interface TasksQueueOptions { /** * Options for a poolifier pool. + * + * @typeParam Worker - The worker type. */ export interface PoolOptions { /** @@ -138,18 +140,6 @@ export interface IPool< * - `'busy'`: Emitted when the pool is busy. */ readonly emitter?: PoolEmitter - /** - * Whether the pool is full or not. - * - * The pool filling boolean status. - */ - readonly full: boolean - /** - * Whether the pool is busy or not. - * - * The pool busyness boolean status. - */ - readonly busy: boolean /** * Finds a free worker node key based on the number of tasks the worker has applied. * diff --git a/src/pools/thread/dynamic.ts b/src/pools/thread/dynamic.ts index 0f901f7f..7bf477dd 100644 --- a/src/pools/thread/dynamic.ts +++ b/src/pools/thread/dynamic.ts @@ -41,12 +41,12 @@ export class DynamicThreadPool< } /** @inheritDoc */ - public get full (): boolean { + protected get full (): boolean { return this.workerNodes.length === this.max } /** @inheritDoc */ - public get busy (): boolean { + protected get busy (): boolean { return this.full && this.internalBusy() } } diff --git a/src/pools/thread/fixed.ts b/src/pools/thread/fixed.ts index 55c35a57..e7d3a727 100644 --- a/src/pools/thread/fixed.ts +++ b/src/pools/thread/fixed.ts @@ -67,7 +67,7 @@ export class FixedThreadPool< } /** @inheritDoc */ - public registerWorkerMessageListener( + protected registerWorkerMessageListener( messageChannel: ThreadWorkerWithMessageChannel, listener: (message: MessageValue) => void ): void { @@ -97,12 +97,12 @@ export class FixedThreadPool< } /** @inheritDoc */ - public get full (): boolean { + protected get full (): boolean { return this.workerNodes.length === this.numberOfWorkers } /** @inheritDoc */ - public get busy (): boolean { + protected get busy (): boolean { return this.internalBusy() } } diff --git a/src/pools/worker.ts b/src/pools/worker.ts index 1f8efbc6..3bb0ac9d 100644 --- a/src/pools/worker.ts +++ b/src/pools/worker.ts @@ -31,6 +31,9 @@ export type ExitHandler = ( /** * Worker task interface. + * + * @typeParam Data - Type of data sent to the worker. This can only be serializable data. + * @internal */ export interface Task { /** @@ -81,9 +84,22 @@ export interface IWorker { /** * Worker node interface. + * + * @typeParam Worker - Type of worker. + * @typeParam Data - Type of data sent to the worker. This can only be serializable data. + * @internal */ export interface WorkerNode { + /** + * Worker node worker. + */ worker: Worker + /** + * Worker node tasks usage statistics. + */ tasksUsage: TasksUsage + /** + * Worker node tasks queue. + */ tasksQueue: Array> } diff --git a/src/utility-types.ts b/src/utility-types.ts index 544b4cd0..685e5c4c 100644 --- a/src/utility-types.ts +++ b/src/utility-types.ts @@ -10,6 +10,9 @@ export type Draft = { -readonly [P in keyof T]?: T[P] } /** * Message object that is passed between worker and main worker. + * + * @typeParam Data - Type of data sent to the worker. This can only be serializable data. + * @typeParam MainWorker - Type of main worker. */ export interface MessageValue< Data = unknown, @@ -49,6 +52,7 @@ export interface MessageValue< * * @typeParam Worker - Type of worker. * @typeParam Response - Type of execution response. This can only be serializable data. + * @internal */ export interface PromiseResponseWrapper< Worker extends IWorker,