- Add `full` event to dynamic pool.
- Keep worker choice strategy usage in memory for conditional reuse.
+### Fixed
+
+- Fix possible negative worker key at worker removal in worker choice strategies.
+
## [2.4.1] - 2023-04-05
### Changed
/** {@inheritDoc} */
public remove (workerKey: number): boolean {
if (this.nextWorkerId === workerKey) {
- this.nextWorkerId =
- this.nextWorkerId > this.pool.workers.length - 1
- ? this.pool.workers.length - 1
- : this.nextWorkerId
+ if (this.pool.workers.length === 0) {
+ this.nextWorkerId = 0
+ } else {
+ this.nextWorkerId =
+ this.nextWorkerId > this.pool.workers.length - 1
+ ? this.pool.workers.length - 1
+ : this.nextWorkerId
+ }
}
return true
}
/** {@inheritDoc} */
public remove (workerKey: number): boolean {
if (this.currentWorkerId === workerKey) {
- this.currentWorkerId =
- this.currentWorkerId > this.pool.workers.length - 1
- ? this.pool.workers.length - 1
- : this.currentWorkerId
+ if (this.pool.workers.length === 0) {
+ this.currentWorkerId = 0
+ } else {
+ this.currentWorkerId =
+ this.currentWorkerId > this.pool.workers.length - 1
+ ? this.pool.workers.length - 1
+ : this.currentWorkerId
+ }
}
const workerDeleted = this.workersTaskRunTime.delete(workerKey)
for (const [key, value] of this.workersTaskRunTime) {