From: Jérôme Benoit Date: Sun, 27 Aug 2023 20:57:09 +0000 (+0200) Subject: refactor: silence sonar code smells X-Git-Tag: v2.6.37~21 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=a9780ad2992ef19ef824da2d796433fc7f193ec8;p=poolifier.git refactor: silence sonar code smells Signed-off-by: Jérôme Benoit --- diff --git a/src/index.ts b/src/index.ts index 67f64f0b..ac7ede0a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,8 +16,6 @@ export type { } from './pools/pool' export { WorkerTypes } from './pools/worker' export type { - BackPressureCallback, - EmptyQueueCallback, ErrorHandler, EventLoopUtilizationMeasurementStatistics, ExitHandler, @@ -28,6 +26,7 @@ export type { OnlineHandler, TaskStatistics, WorkerInfo, + WorkerNodeEventCallback, WorkerType, WorkerUsage } from './pools/worker' diff --git a/src/pools/pool.ts b/src/pools/pool.ts index 4463560c..7a103733 100644 --- a/src/pools/pool.ts +++ b/src/pools/pool.ts @@ -208,7 +208,7 @@ export interface IPool< * Events that can currently be listened to: * * - `'ready'`: Emitted when the number of workers created in the pool has reached the minimum size expected and are ready. - * - `'busy'`: Emitted when the number of workers created in the pool has reached the maximum size expected and are executing at least one task. + * - `'busy'`: Emitted when the number of workers created in the pool has reached the maximum size expected and are executing concurrently their tasks quota. * - `'full'`: Emitted when the pool is dynamic and the number of workers created has reached the maximum size expected. * - `'destroy'`: Emitted when the pool is destroyed. * - `'error'`: Emitted when an uncaught error occurs. diff --git a/src/pools/worker-node.ts b/src/pools/worker-node.ts index 45b4f1ee..f9b4016c 100644 --- a/src/pools/worker-node.ts +++ b/src/pools/worker-node.ts @@ -11,11 +11,10 @@ import { } from '../utils' import { Deque } from '../deque' import { - type BackPressureCallback, - type EmptyQueueCallback, type IWorker, type IWorkerNode, type WorkerInfo, + type WorkerNodeEventCallback, type WorkerType, WorkerTypes, type WorkerUsage @@ -40,9 +39,9 @@ implements IWorkerNode { /** @inheritdoc */ public tasksQueueBackPressureSize: number /** @inheritdoc */ - public onBackPressure?: BackPressureCallback + public onBackPressure?: WorkerNodeEventCallback /** @inheritdoc */ - public onEmptyQueue?: EmptyQueueCallback + public onEmptyQueue?: WorkerNodeEventCallback private readonly tasksQueue: Deque> private onEmptyQueueCount: number private readonly taskFunctionsUsage: Map @@ -179,7 +178,7 @@ implements IWorkerNode { this.onEmptyQueueCount = 0 return } - (this.onEmptyQueue as EmptyQueueCallback)(this.info.id as number) + (this.onEmptyQueue as WorkerNodeEventCallback)(this.info.id as number) ++this.onEmptyQueueCount await sleep(exponentialDelay(this.onEmptyQueueCount)) await this.startOnEmptyQueue() diff --git a/src/pools/worker.ts b/src/pools/worker.ts index 7a8c59e7..be134f05 100644 --- a/src/pools/worker.ts +++ b/src/pools/worker.ts @@ -199,8 +199,7 @@ export interface IWorker { readonly once: (event: 'exit', handler: ExitHandler) => void } -export type EmptyQueueCallback = (workerId: number) => void -export type BackPressureCallback = EmptyQueueCallback +export type WorkerNodeEventCallback = (workerId: number) => void /** * Worker node interface. @@ -236,13 +235,13 @@ export interface IWorkerNode { * * @param workerId - The worker id. */ - onBackPressure?: EmptyQueueCallback + onBackPressure?: WorkerNodeEventCallback /** * Callback invoked when worker node tasks queue is empty. * * @param workerId - The worker id. */ - onEmptyQueue?: BackPressureCallback + onEmptyQueue?: WorkerNodeEventCallback /** * Tasks queue size. *