build(ci): refine autofix GH action
[poolifier.git] / src / worker / utils.ts
index f88ead7dcbcd238cb990ebaed48e23f625201c4c..59a0289b79e78e9a9020257b872aca0c95486999 100644 (file)
@@ -1,8 +1,14 @@
-import { isPlainObject } from '../utils'
-import type { TaskFunction } from './task-functions'
-import { KillBehaviors, type WorkerOptions } from './worker-options'
+import {
+  checkValidPriority,
+  checkValidWorkerChoiceStrategy,
+} from '../pools/utils.js'
+import { isPlainObject } from '../utils.js'
+import type { TaskFunctionObject } from './task-functions.js'
+import { KillBehaviors, type WorkerOptions } from './worker-options.js'
 
-export const checkValidWorkerOptions = (opts: WorkerOptions): void => {
+export const checkValidWorkerOptions = (
+  opts: WorkerOptions | undefined
+): void => {
   if (opts != null && !isPlainObject(opts)) {
     throw new TypeError('opts worker options parameter is not a plain object')
   }
@@ -28,15 +34,15 @@ export const checkValidWorkerOptions = (opts: WorkerOptions): void => {
   if (opts?.killHandler != null && typeof opts.killHandler !== 'function') {
     throw new TypeError('killHandler option is not a function')
   }
-  if (opts?.async != null) {
-    throw new Error('async option is deprecated')
-  }
 }
 
-export const checkValidTaskFunctionEntry = <Data = unknown, Response = unknown>(
-  name: string,
-  fn: TaskFunction<Data, Response>
-): void => {
+export const checkValidTaskFunctionObjectEntry = <
+  Data = unknown,
+  Response = unknown
+>(
+    name: string,
+    fnObj: TaskFunctionObject<Data, Response>
+  ): void => {
   if (typeof name !== 'string') {
     throw new TypeError('A taskFunctions parameter object key is not a string')
   }
@@ -45,11 +51,14 @@ export const checkValidTaskFunctionEntry = <Data = unknown, Response = unknown>(
       'A taskFunctions parameter object key is an empty string'
     )
   }
-  if (typeof fn !== 'function') {
+  if (typeof fnObj.taskFunction !== 'function') {
     throw new TypeError(
-      'A taskFunctions parameter object value is not a function'
+      // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
+      `taskFunction object 'taskFunction' property '${fnObj.taskFunction}' is not a function`
     )
   }
+  checkValidPriority(fnObj.priority)
+  checkValidWorkerChoiceStrategy(fnObj.strategy)
 }
 
 export const checkTaskFunctionName = (name: string): void => {