Implement PR reviews
authoraardizio <alessandroardizio94@gmail.com>
Mon, 15 Feb 2021 18:37:12 +0000 (19:37 +0100)
committeraardizio <alessandroardizio94@gmail.com>
Mon, 15 Feb 2021 18:37:12 +0000 (19:37 +0100)
CHANGELOG.md
src/pools/abstract-pool.ts
src/pools/cluster/dynamic.ts
src/pools/thread/dynamic.ts

index 12fd3608b50babfda765bb43aceaad9a311a0b34..67a447c326a204331de30339025b3c4ce75ced09 100644 (file)
@@ -8,7 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 ## [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.
index 879e3e4f78f2b3ab60a5918a865fa7c711e3d882..0685f998d4aaf11d0cb93d86fcdb24b0e3476fbc 100644 (file)
@@ -190,23 +190,23 @@ export abstract class AbstractPool<
    * @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')
     }
index f6c70126f41599b482c6a653923dad3a66bed964..5eba843a3ae0726a3102d3068deced8679058844 100644 (file)
@@ -62,7 +62,9 @@ export class DynamicClusterPool<
     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)
       }
index 74013f2b70dceaf0e35ece2bbd9c25c5d0168701..26d81d2fc15c99aa33a12088e225ab0889f534f4 100644 (file)
@@ -62,9 +62,9 @@ export class DynamicThreadPool<
     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)
       }