X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2Futils.ts;h=d0883893581b0a14c24cb415bef585541b71c446;hb=refs%2Fheads%2Fmaster;hp=e023cc37588cc8d85b86400872d0f4ee3a2ef234;hpb=277c49bfd06bfacb4f18211fb0a3c1803cd33701;p=poolifier.git diff --git a/src/worker/utils.ts b/src/worker/utils.ts index e023cc37..59a0289b 100644 --- a/src/worker/utils.ts +++ b/src/worker/utils.ts @@ -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') } @@ -30,10 +36,13 @@ export const checkValidWorkerOptions = (opts: WorkerOptions): void => { } } -export const checkValidTaskFunctionEntry = ( - name: string, - fn: TaskFunction -): void => { +export const checkValidTaskFunctionObjectEntry = < + Data = unknown, + Response = unknown +>( + name: string, + fnObj: TaskFunctionObject + ): void => { if (typeof name !== 'string') { throw new TypeError('A taskFunctions parameter object key is not a string') } @@ -42,11 +51,14 @@ export const checkValidTaskFunctionEntry = ( '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 => {