refactor: silence sonar code smells
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 27 Aug 2023 20:57:09 +0000 (22:57 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 27 Aug 2023 20:57:09 +0000 (22:57 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/index.ts
src/pools/pool.ts
src/pools/worker-node.ts
src/pools/worker.ts

index 67f64f0b3ca91bdb853aafffa4b38fd47955a46a..ac7ede0a746be1e5cfec0df8275aaeb7e72f9eff 100644 (file)
@@ -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'
index 4463560c2754e82fd8b14564bd7c18a3268dc671..7a10373393786ac56c0e7f9a98b69f81639cbbe1 100644 (file)
@@ -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.
index 45b4f1ee18c041db8837ecc987c4d5cba38e998d..f9b4016c29b078143d6f56d9acfcaf24b06e688d 100644 (file)
@@ -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<Worker, Data> {
   /** @inheritdoc */
   public tasksQueueBackPressureSize: number
   /** @inheritdoc */
-  public onBackPressure?: BackPressureCallback
+  public onBackPressure?: WorkerNodeEventCallback
   /** @inheritdoc */
-  public onEmptyQueue?: EmptyQueueCallback
+  public onEmptyQueue?: WorkerNodeEventCallback
   private readonly tasksQueue: Deque<Task<Data>>
   private onEmptyQueueCount: number
   private readonly taskFunctionsUsage: Map<string, WorkerUsage>
@@ -179,7 +178,7 @@ implements IWorkerNode<Worker, Data> {
       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()
index 7a8c59e7730eba9be39ae972f94022a8a65a14ce..be134f05f539b87bf254bbfb71e68c90e360946c 100644 (file)
@@ -199,8 +199,7 @@ export interface IWorker {
   readonly once: (event: 'exit', handler: ExitHandler<this>) => 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<Worker extends IWorker, Data = unknown> {
    *
    * @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.
    *