### Changed
+- Support per task function(s) priority and worker choice strategy definition via a task function object: `{ taskFunction: (data?: Data) => Response | Promise<Response>, priority?: number, strategy?: WorkerChoiceStrategy }`.
+- Add priority queue based tasks queueing. One priority queue is divided into prioritized buckets to avoid queued tasks starvation under load.
- BREAKING CHANGE: `listTaskFunctionNames()` to `listTaskFunctionsProperties()` in pool and worker API returning registered task functions properties.
+- BREAKING CHANGE: `strategy` field in pool information renamed to `defaultStrategy`.
+
+### Fixed
+
+- Ensure worker choice strategy options changes at runtime are propagated to poolifier workers.
## [3.1.30] - 2024-04-22
-### Fixed:
+### Fixed
- Fix `transferList` argument type definition.
- Proper integration with Node.js [async_hooks](https://nodejs.org/api/async_hooks.html) :white_check_mark:
- Support for CommonJS, ESM and TypeScript :white_check_mark:
- Support for [worker_threads](https://nodejs.org/api/worker_threads.html) and [cluster](https://nodejs.org/api/cluster.html) Node.js modules :white_check_mark:
-- Support for multiple task functions :white_check_mark:
+- Support for multiple task functions with per task function queuing priority and tasks distribution strategy :white_check_mark:
- Support for task functions [CRUD](https://en.wikipedia.org/wiki/Create,_read,_update_and_delete) operations at runtime :white_check_mark:
- Support for sync and async task functions :white_check_mark:
- Tasks distribution strategies :white_check_mark:
### `pool.addTaskFunction(name, fn)`
`name` (mandatory) The task function name.
-`fn` (mandatory) The task function.
+`fn` (mandatory) The task function `(data?: Data) => Response | Promise<Response>` or task function object `{ taskFunction: (data?: Data) => Response | Promise<Response>, priority?: number, strategy?: WorkerChoiceStrategy }`. Priority range is the same as Unix nice levels.
This method is available on both pool implementations and returns a boolean promise.
### `class YourWorker extends ThreadWorker/ClusterWorker`
-`taskFunctions` (mandatory) The task function or task functions object `{ name_1: fn_1, ..., name_n: fn_n }` that you want to execute on the worker.
+`taskFunctions` (mandatory) The task function or task functions object `Record<string, (data?: Data) => Response | Promise<Response> | { taskFunction: (data?: Data) => Response | Promise<Response>, priority?: number, strategy?: WorkerChoiceStrategy }>` that you want to execute on the worker. Priority range is the same as Unix nice levels.
`opts` (optional) An object with these properties:
- `killBehavior` (optional) - Dictates if your worker will be deleted in case a task is active on it.
#### `YourWorker.addTaskFunction(name, fn)`
`name` (mandatory) The task function name.
-`fn` (mandatory) The task function.
+`fn` (mandatory) The task function `(data?: Data) => Response | Promise<Response>` or task function object `{ taskFunction: (data?: Data) => Response | Promise<Response>, priority?: number, strategy?: WorkerChoiceStrategy }`. Priority range is the same as Unix nice levels.
This method is available on both worker implementations and returns `{ status: boolean, error?: Error }`.