refactor: move helpers to utils.ts file
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 2 Jul 2023 16:47:20 +0000 (18:47 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 2 Jul 2023 16:47:20 +0000 (18:47 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/pools/abstract-pool.ts
src/utils.ts
src/worker/worker-options.ts
tests/utils.test.js

index 52a2aa383da0dd89acf4b3db7e518fd18fc33f21..24e8a5b0c670f275a91a93dec22227fa12659d25 100644 (file)
@@ -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 {
index 7ac4ab25db67446a49b2fc42a0f219c043d4af6f..1b657bce22acaf49a39552f411f1bc4899834777 100644 (file)
@@ -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 = <KB extends KillBehavior>(
+  killBehavior: KB,
+  value: unknown
+): value is KB => {
+  return value === killBehavior
+}
index 90aea1efc04e9c2d5015b910909831bc4b71f4af..75d3dd5b98bf1d8e633d3b58c0190cd3c1f20f93 100644 (file)
@@ -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 = <KB extends KillBehavior>(
-  killBehavior: KB,
-  value: unknown
-): value is KB => {
-  return value === killBehavior
-}
-
 /**
  * Options for workers.
  */
index 0bf5e50ca8a4989099500100ff2b097a96092713..7ad3a5c7efee2cf217c47f556faa92ca4671229a 100644 (file)
@@ -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', () => {