From: Jérôme Benoit Date: Sun, 2 Jul 2023 16:47:20 +0000 (+0200) Subject: refactor: move helpers to utils.ts file X-Git-Tag: v2.6.7~15 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=5931725336d0de8a06146641ae6feef22bf60e6e;p=poolifier.git refactor: move helpers to utils.ts file Signed-off-by: Jérôme Benoit --- 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', () => {