3 checkValidWorkerChoiceStrategy
,
4 } from
'../pools/utils.js'
5 import { isPlainObject
} from
'../utils.js'
6 import type { TaskFunctionObject
} from
'./task-functions.js'
7 import { KillBehaviors
, type WorkerOptions
} from
'./worker-options.js'
9 export const checkValidWorkerOptions
= (
10 opts
: WorkerOptions
| undefined
12 if (opts
!= null && !isPlainObject(opts
)) {
13 throw new TypeError('opts worker options parameter is not a plain object')
16 opts
?.killBehavior
!= null &&
17 !Object.values(KillBehaviors
).includes(opts
.killBehavior
)
20 `killBehavior option '${opts.killBehavior}' is not valid`
24 opts
?.maxInactiveTime
!= null &&
25 !Number.isSafeInteger(opts
.maxInactiveTime
)
27 throw new TypeError('maxInactiveTime option is not an integer')
29 if (opts
?.maxInactiveTime
!= null && opts
.maxInactiveTime
< 5) {
31 'maxInactiveTime option is not a positive integer greater or equal than 5'
34 if (opts
?.killHandler
!= null && typeof opts
.killHandler
!== 'function') {
35 throw new TypeError('killHandler option is not a function')
39 export const checkValidTaskFunctionObjectEntry
= <
44 fnObj
: TaskFunctionObject
<Data
, Response
>
46 if (typeof name
!== 'string') {
47 throw new TypeError('A taskFunctions parameter object key is not a string')
49 if (typeof name
=== 'string' && name
.trim().length
=== 0) {
51 'A taskFunctions parameter object key is an empty string'
54 if (typeof fnObj
.taskFunction
!== 'function') {
56 `taskFunction object 'taskFunction' property '${fnObj.taskFunction}' is not a function`
59 checkValidPriority(fnObj
.priority
)
60 checkValidWorkerChoiceStrategy(fnObj
.strategy
)
63 export const checkTaskFunctionName
= (name
: string): void => {
64 if (typeof name
!== 'string') {
65 throw new TypeError('name parameter is not a string')
67 if (typeof name
=== 'string' && name
.trim().length
=== 0) {
68 throw new TypeError('name parameter is an empty string')