This method is available on both worker implementations and returns a boolean.
+#### `YourWorker.listTaskFunctions()`
+
+This method is available on both worker implementations and returns an array of the task function names.
+
#### `YourWorker.setDefaultTaskFunction(name)`
`name` (mandatory) The task function name
## General guidance
Performance is one of the main target of these worker pool implementations, we want to have a strong focus on this.
-We already have a benchmarks folder where you can find some comparisons.
+We already have a [benchmarks](./benchmarks/) folder where you can find some comparisons.
### Internal Node.js thread pool
)
}
const boundFn = fn.bind(this)
- this.taskFunctions.set(name, boundFn)
if (firstEntry) {
this.taskFunctions.set(DEFAULT_TASK_NAME, boundFn)
firstEntry = false
}
+ this.taskFunctions.set(name, boundFn)
}
if (firstEntry) {
throw new Error('taskFunctions parameter object is empty')
}
/**
- * Sets the default task function to use when no task function name is specified.
+ * Lists the names of the worker's task functions.
+ *
+ * @returns The names of the worker's task functions.
+ */
+ public listTaskFunctions (): string[] {
+ return Array.from(this.taskFunctions.keys())
+ }
+
+ /**
+ * Sets the default task function to use in the worker.
*
* @param name - The name of the task function to use as default task function.
* @returns Whether the default task function was set or not.
expect(worker.taskFunctions.size).toBe(2)
})
+ it('Verify that listTaskFunctions() works', () => {
+ const fn1 = () => {
+ return 1
+ }
+ const fn2 = () => {
+ return 2
+ }
+ const worker = new ClusterWorker({ fn1, fn2 })
+ expect(worker.listTaskFunctions()).toStrictEqual(['default', 'fn1', 'fn2'])
+ })
+
it('Verify that setDefaultTaskFunction() works', () => {
const fn1 = () => {
return 1