From 5931725336d0de8a06146641ae6feef22bf60e6e Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 2 Jul 2023 18:47:20 +0200 Subject: [PATCH] refactor: move helpers to utils.ts file MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/pools/abstract-pool.ts | 3 ++- src/utils.ts | 16 ++++++++++++++++ src/worker/worker-options.ts | 15 --------------- tests/utils.test.js | 6 ++---- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 52a2aa38..24e8a5b0 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -4,11 +4,12 @@ import type { MessageValue, PromiseResponseWrapper } from '../utility-types' import { DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS, EMPTY_FUNCTION, + isKillBehavior, isPlainObject, median, round } from '../utils' -import { KillBehaviors, isKillBehavior } from '../worker/worker-options' +import { KillBehaviors } from '../worker/worker-options' import { CircularArray } from '../circular-array' import { Queue } from '../queue' import { diff --git a/src/utils.ts b/src/utils.ts index 7ac4ab25..1b657bce 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -3,6 +3,7 @@ import type { MeasurementStatisticsRequirements, WorkerChoiceStrategyOptions } from './pools/selection-strategies/selection-strategies-types' +import type { KillBehavior } from './worker/worker-options' /** * An intentional empty function. @@ -95,3 +96,18 @@ export const isPlainObject = (obj: unknown): boolean => obj !== null && obj?.constructor === Object && Object.prototype.toString.call(obj) === '[object Object]' + +/** + * Detects whether the given value is a kill behavior or not. + * + * @typeParam KB - Which specific KillBehavior type to test against. + * @param killBehavior - Which kind of kill behavior to detect. + * @param value - Any value. + * @returns `true` if `value` was strictly equals to `killBehavior`, otherwise `false`. + */ +export const isKillBehavior = ( + killBehavior: KB, + value: unknown +): value is KB => { + return value === killBehavior +} diff --git a/src/worker/worker-options.ts b/src/worker/worker-options.ts index 90aea1ef..75d3dd5b 100644 --- a/src/worker/worker-options.ts +++ b/src/worker/worker-options.ts @@ -17,21 +17,6 @@ export const KillBehaviors = Object.freeze({ */ export type KillBehavior = keyof typeof KillBehaviors -/** - * Detects whether the given value is a kill behavior or not. - * - * @typeParam KB - Which specific KillBehavior type to test against. - * @param killBehavior - Which kind of kill behavior to detect. - * @param value - Any value. - * @returns `true` if `value` was strictly equals to `killBehavior`, otherwise `false`. - */ -export const isKillBehavior = ( - killBehavior: KB, - value: unknown -): value is KB => { - return value === killBehavior -} - /** * Options for workers. */ diff --git a/tests/utils.test.js b/tests/utils.test.js index 0bf5e50c..7ad3a5c7 100644 --- a/tests/utils.test.js +++ b/tests/utils.test.js @@ -1,14 +1,12 @@ const { expect } = require('expect') const { availableParallelism, + isKillBehavior, isPlainObject, median, round } = require('../lib/utils') -const { - isKillBehavior, - KillBehaviors -} = require('../lib/worker/worker-options') +const { KillBehaviors } = require('../lib/worker/worker-options') describe('Utils test suite', () => { it('Verify availableParallelism() behavior', () => { -- 2.34.1