## [2.0.0] - not released yet
### Bug fixes
- - Now a thread/process is not delete when the task submitted take more time than maxInactiveTime configured( issue #70)
+
+- Now a thread/process is not delete when the task submitted take more time than maxInactiveTime configured (issue #70)
+
### Breaking Changes
We changed some internal structures, but you shouldn't be too affected by them as these are internal changes.
* @param worker Workers whose tasks are increased.
*/
protected increaseWorkersTask (worker: Worker): void {
- const numberOfTasksTheWorkerHas = this.tasks.get(worker)
- if (numberOfTasksTheWorkerHas !== undefined) {
- this.tasks.set(worker, numberOfTasksTheWorkerHas + 1)
+ const numberOfTasksInProgress = this.tasks.get(worker)
+ if (numberOfTasksInProgress !== undefined) {
+ this.tasks.set(worker, numberOfTasksInProgress + 1)
} else {
throw Error('Worker could not be found in tasks map')
}
}
/**
- * Increase the number of tasks that the given workers has done.
+ * Decrease the number of tasks that the given workers has done.
*
- * @param worker Workers whose tasks are increased.
+ * @param worker Workers whose tasks are decreased.
*/
protected decreaseWorkersTasks (worker: Worker): void {
- const numberOfTasksTheWorkerHas = this.tasks.get(worker)
- if (numberOfTasksTheWorkerHas !== undefined) {
- this.tasks.set(worker, numberOfTasksTheWorkerHas - 1)
+ const numberOfTasksInProgress = this.tasks.get(worker)
+ if (numberOfTasksInProgress !== undefined) {
+ this.tasks.set(worker, numberOfTasksInProgress - 1)
} else {
throw Error('Worker could not be found in tasks map')
}
const worker = this.createAndSetupWorker()
this.registerWorkerMessageListener<Data>(worker, message => {
const tasksInProgress = this.tasks.get(worker)
- if (message.kill && !tasksInProgress) {
+ if (message.kill && tasksInProgress === 0) {
+ // Kill received from the worker, means that no new tasks are submitted to that worker for a while ( > maxInactiveTime)
+ // To handle the case of a long-running task we will check if there is any active task
this.sendToWorker(worker, { kill: 1 })
void this.destroyWorker(worker)
}
const worker = this.createAndSetupWorker()
this.registerWorkerMessageListener<Data>(worker, message => {
const tasksInProgress = this.tasks.get(worker)
- if (message.kill && !tasksInProgress) {
- // Kill received from the worker, means that no new tasks are submitted to that worker for a while( > maxInactiveTime)
- // To handle the case of a long-running task we will check if the there is any active task
+ if (message.kill && tasksInProgress === 0) {
+ // Kill received from the worker, means that no new tasks are submitted to that worker for a while ( > maxInactiveTime)
+ // To handle the case of a long-running task we will check if there is any active task
this.sendToWorker(worker, { kill: 1 })
void this.destroyWorker(worker)
}