From: Jérôme Benoit Date: Mon, 29 May 2023 21:04:21 +0000 (+0200) Subject: feat: switch event emission to async context friendly alternative X-Git-Tag: v2.5.0~15 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=9e45c2c437217612e71b46b207a994f9106dff23;p=poolifier.git feat: switch event emission to async context friendly alternative Signed-off-by: Jérôme Benoit --- diff --git a/README.md b/README.md index 18b0d78a..3eeebed1 100644 --- a/README.md +++ b/README.md @@ -145,7 +145,7 @@ Remember that workers can only send and receive serializable data. ## Node versions -Node versions >= 16.x are supported. +Node versions >= 16.14.x are supported. ## [API](https://poolifier.github.io/poolifier/) @@ -173,7 +173,7 @@ Node versions >= 16.x are supported. - `workerChoiceStrategyOptions` (optional) - The worker choice strategy options object to use in this pool. Properties: - - `medRunTime` (optional) - Use the tasks median run time instead of the tasks average run time in worker choice strategies. + - `medRunTime` (optional) - Use the tasks median runtime instead of the tasks average runtime in worker choice strategies. - `weights` (optional) - The worker weights to use in the weighted round robin worker choice strategy: `{ 0: 200, 1: 300, ..., n: 100 }` Default: `{ medRunTime: false }` diff --git a/benchmarks/versus-external-pools/package.json b/benchmarks/versus-external-pools/package.json index 9d1ecc6b..b466e3c6 100644 --- a/benchmarks/versus-external-pools/package.json +++ b/benchmarks/versus-external-pools/package.json @@ -6,7 +6,7 @@ "main": "index.js", "author": "pioardi", "engines": { - "node": ">=14.14.0", + "node": ">=16.14.0", "pnpm": ">=8.6.0" }, "volta": { diff --git a/package.json b/package.json index 16edd5ca..6a189663 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ ] }, "engines": { - "node": ">=16.0.0", + "node": ">=16.14.0", "pnpm": ">=8.6.0" }, "volta": { diff --git a/src/pools/pool.ts b/src/pools/pool.ts index 0a015476..14b30812 100644 --- a/src/pools/pool.ts +++ b/src/pools/pool.ts @@ -1,4 +1,4 @@ -import EventEmitter from 'node:events' +import EventEmitterAsyncResource from 'node:events' import type { ErrorHandler, ExitHandler, @@ -32,7 +32,7 @@ export enum PoolType { /** * Pool events emitter. */ -export class PoolEmitter extends EventEmitter {} +export class PoolEmitter extends EventEmitterAsyncResource {} /** * Enumeration of pool events. diff --git a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts index a4455d28..d969f0c0 100644 --- a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts @@ -88,12 +88,12 @@ export abstract class AbstractWorkerChoiceStrategy< } /** - * Gets the worker task run time. - * If the required statistics are `avgRunTime`, the average run time is returned. - * If the required statistics are `medRunTime`, the median run time is returned. + * Gets the worker task runtime. + * If the required statistics are `avgRunTime`, the average runtime is returned. + * If the required statistics are `medRunTime`, the median runtime is returned. * * @param workerNodeKey - The worker node key. - * @returns The worker task run time. + * @returns The worker task runtime. */ protected getWorkerTaskRunTime (workerNodeKey: number): number { return this.requiredStatistics.medRunTime diff --git a/src/pools/selection-strategies/selection-strategies-types.ts b/src/pools/selection-strategies/selection-strategies-types.ts index b95cf7f3..659706ce 100644 --- a/src/pools/selection-strategies/selection-strategies-types.ts +++ b/src/pools/selection-strategies/selection-strategies-types.ts @@ -34,7 +34,7 @@ export type WorkerChoiceStrategy = keyof typeof WorkerChoiceStrategies */ export interface WorkerChoiceStrategyOptions { /** - * Use tasks median run time instead of average run time. + * Use tasks median runtime instead of average runtime. * * @defaultValue false */ diff --git a/tests/pools/selection-strategies/worker-choice-strategy-context.test.js b/tests/pools/selection-strategies/worker-choice-strategy-context.test.js index f04013d9..fa380a5a 100644 --- a/tests/pools/selection-strategies/worker-choice-strategy-context.test.js +++ b/tests/pools/selection-strategies/worker-choice-strategy-context.test.js @@ -322,7 +322,7 @@ describe('Worker choice strategy context test suite', () => { ) }) - it('Verify that worker choice strategy options enable median run time pool statistics', () => { + it('Verify that worker choice strategy options enable median runtime pool statistics', () => { const wwrWorkerChoiceStrategy = WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN let workerChoiceStrategyContext = new WorkerChoiceStrategyContext( fixedPool,