From: Jérôme Benoit Date: Wed, 12 Apr 2023 20:16:04 +0000 (+0200) Subject: docs: enhance documentation and update changelog entries X-Git-Tag: v2.4.8~4 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=f9b4bbf801547d7e17bf43e2e586ac956e97e1b0;p=poolifier.git docs: enhance documentation and update changelog entries Signed-off-by: Jérôme Benoit --- diff --git a/CHANGELOG.md b/CHANGELOG.md index 8dc984df..ce8ccdc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 3be40e6d..1c59f74b 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -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: [] }) } diff --git a/src/pools/worker.ts b/src/pools/worker.ts index 05b55985..82aed552 100644 --- a/src/pools/worker.ts +++ b/src/pools/worker.ts @@ -48,6 +48,8 @@ export interface Task { /** * Worker tasks usage statistics. + * + * @internal */ export interface TasksUsage { /** diff --git a/src/utils.ts b/src/utils.ts index fc328a6c..1d7f81d2 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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. */