This method is available on both pool implementations and will call the terminate method on each worker.
+### `pool.hasTaskFunction(name)`
+
+`name` (mandatory) The task function name
+
+This method is available on both pool implementations and returns a boolean.
+
### `pool.listTaskFunctionNames()`
This method is available on both pool implementations and returns an array of the task function names.
`name` (mandatory) The task function name
-This method is available on both worker implementations and returns a boolean.
+This method is available on both worker implementations and returns `{ status: boolean, error?: Error }`.
#### `YourWorker.addTaskFunction(name, fn)`
`name` (mandatory) The task function name
`fn` (mandatory) The task function
-This method is available on both worker implementations and returns a boolean.
+This method is available on both worker implementations and returns `{ status: boolean, error?: Error }`.
#### `YourWorker.removeTaskFunction(name)`
`name` (mandatory) The task function name
-This method is available on both worker implementations and returns a boolean.
+This method is available on both worker implementations and returns `{ status: boolean, error?: Error }`.
#### `YourWorker.listTaskFunctionNames()`
`name` (mandatory) The task function name
-This method is available on both worker implementations and returns a boolean.
+This method is available on both worker implementations and returns `{ status: boolean, error?: Error }`.
await pool.destroy()
})
- it('Verify that listTaskFunctions() is working', async () => {
+ it('Verify that listTaskFunctionNames() is working', async () => {
const dynamicThreadPool = new DynamicThreadPool(
Math.floor(numberOfWorkers / 2),
numberOfWorkers,
await fixedClusterPool.destroy()
})
+ it('Verify that hasTaskFunction() is working', async () => {
+ const dynamicThreadPool = new DynamicThreadPool(
+ Math.floor(numberOfWorkers / 2),
+ numberOfWorkers,
+ './tests/worker-files/thread/testMultipleTaskFunctionsWorker.js'
+ )
+ await waitPoolEvents(dynamicThreadPool, PoolEvents.ready, 1)
+ expect(dynamicThreadPool.hasTaskFunction(DEFAULT_TASK_NAME)).toBe(true)
+ expect(dynamicThreadPool.hasTaskFunction('jsonIntegerSerialization')).toBe(
+ true
+ )
+ expect(dynamicThreadPool.hasTaskFunction('factorial')).toBe(true)
+ expect(dynamicThreadPool.hasTaskFunction('fibonacci')).toBe(true)
+ expect(dynamicThreadPool.hasTaskFunction('unknown')).toBe(false)
+ const fixedClusterPool = new FixedClusterPool(
+ numberOfWorkers,
+ './tests/worker-files/cluster/testMultipleTaskFunctionsWorker.js'
+ )
+ await waitPoolEvents(fixedClusterPool, PoolEvents.ready, 1)
+ expect(dynamicThreadPool.hasTaskFunction(DEFAULT_TASK_NAME)).toBe(true)
+ expect(dynamicThreadPool.hasTaskFunction('jsonIntegerSerialization')).toBe(
+ true
+ )
+ expect(dynamicThreadPool.hasTaskFunction('factorial')).toBe(true)
+ expect(dynamicThreadPool.hasTaskFunction('fibonacci')).toBe(true)
+ expect(dynamicThreadPool.hasTaskFunction('unknown')).toBe(false)
+ await dynamicThreadPool.destroy()
+ await fixedClusterPool.destroy()
+ })
+
it('Verify that multiple task functions worker is working', async () => {
const pool = new DynamicClusterPool(
Math.floor(numberOfWorkers / 2),