docs: enhance documentation and update changelog entries
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 12 Apr 2023 20:16:04 +0000 (22:16 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 12 Apr 2023 20:16:04 +0000 (22:16 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
CHANGELOG.md
src/pools/abstract-pool.ts
src/pools/worker.ts
src/utils.ts

index 8dc984df4de43740d0feb697a57b17c63d347617..ce8ccdc41c95af61b7314a2914ef46d166d67674 100644 (file)
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ## [Unreleased]
 
+### Fixed
+
+- Fix message between main worker and worker type definition for tasks.
+- Fix code documentation.
+
 ## [2.4.7] - 2023-04-11
 
 ### Added
index 3be40e6d9cc8dd2634ab02569abd6261dca6f326..1c59f74b22b1eaf811e3a9dc0cf3d6bbbd150206 100644 (file)
@@ -3,6 +3,7 @@ import type { MessageValue, PromiseResponseWrapper } from '../utility-types'
 import {
   DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS,
   EMPTY_FUNCTION,
+  INITIAL_TASKS_USAGE,
   median
 } from '../utils'
 import { KillBehaviors, isKillBehavior } from '../worker/worker-options'
@@ -20,7 +21,6 @@ import {
   type WorkerChoiceStrategy
 } from './selection-strategies/selection-strategies-types'
 import { WorkerChoiceStrategyContext } from './selection-strategies/worker-choice-strategy-context'
-import { CircularArray } from '../circular-array'
 
 /**
  * Base class that implements some shared logic for all poolifier pools.
@@ -212,15 +212,7 @@ export abstract class AbstractPool<
     this.checkValidWorkerChoiceStrategy(workerChoiceStrategy)
     this.opts.workerChoiceStrategy = workerChoiceStrategy
     for (const workerNode of this.workerNodes) {
-      this.setWorkerNodeTasksUsage(workerNode, {
-        run: 0,
-        running: 0,
-        runTime: 0,
-        runTimeHistory: new CircularArray(),
-        avgRunTime: 0,
-        medRunTime: 0,
-        error: 0
-      })
+      this.setWorkerNodeTasksUsage(workerNode, INITIAL_TASKS_USAGE)
     }
     this.workerChoiceStrategyContext.setWorkerChoiceStrategy(
       workerChoiceStrategy
@@ -526,15 +518,7 @@ export abstract class AbstractPool<
   private pushWorkerNode (worker: Worker): number {
     return this.workerNodes.push({
       worker,
-      tasksUsage: {
-        run: 0,
-        running: 0,
-        runTime: 0,
-        runTimeHistory: new CircularArray(),
-        avgRunTime: 0,
-        medRunTime: 0,
-        error: 0
-      },
+      tasksUsage: INITIAL_TASKS_USAGE,
       tasksQueue: []
     })
   }
index 05b559850c3a16f4d682f25acaf42e20a3f982e0..82aed5526c976a1d05691dd04d922d4f33bcd5ee 100644 (file)
@@ -48,6 +48,8 @@ export interface Task<Data = unknown> {
 
 /**
  * Worker tasks usage statistics.
+ *
+ * @internal
  */
 export interface TasksUsage {
   /**
index fc328a6c688e2d85f04a04be0e4874584ad5c57c..1d7f81d2d19fb41397a5ecdcbacde6d2d5076dd0 100644 (file)
@@ -1,4 +1,6 @@
+import { CircularArray } from './circular-array'
 import type { WorkerChoiceStrategyOptions } from './pools/selection-strategies/selection-strategies-types'
+import type { TasksUsage } from './pools/worker'
 
 /**
  * An intentional empty function.
@@ -7,6 +9,19 @@ export const EMPTY_FUNCTION: () => void = Object.freeze(() => {
   /* Intentionally empty */
 })
 
+/**
+ * Initial tasks usage statistics.
+ */
+export const INITIAL_TASKS_USAGE: TasksUsage = {
+  run: 0,
+  running: 0,
+  runTime: 0,
+  runTimeHistory: new CircularArray(),
+  avgRunTime: 0,
+  medRunTime: 0,
+  error: 0
+}
+
 /**
  * Default worker choice strategy options.
  */