refactor: factor out last task timestamp update
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 17 Jul 2023 13:27:51 +0000 (15:27 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 17 Jul 2023 13:27:51 +0000 (15:27 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/worker/abstract-worker.ts

index 7d5494deeb3bbe80d2a725bd6ef0d685ca288775..2f4212f9cc884e5b63745949ae3bf521b2ab1b57 100644 (file)
@@ -333,7 +333,10 @@ export abstract class AbstractWorker<
    * Stops the worker check active interval.
    */
   private stopCheckActive (): void {
-    this.activeInterval != null && clearInterval(this.activeInterval)
+    if (this.activeInterval != null) {
+      clearInterval(this.activeInterval)
+      delete this.activeInterval
+    }
   }
 
   /**
@@ -426,9 +429,7 @@ export abstract class AbstractWorker<
         id: task.id
       })
     } finally {
-      if (!this.isMain && this.activeInterval != null) {
-        this.lastTaskTimestamp = performance.now()
-      }
+      this.updateLastTaskTimestamp()
     }
   }
 
@@ -467,9 +468,7 @@ export abstract class AbstractWorker<
         })
       })
       .finally(() => {
-        if (!this.isMain && this.activeInterval != null) {
-          this.lastTaskTimestamp = performance.now()
-        }
+        this.updateLastTaskTimestamp()
       })
       .catch(EMPTY_FUNCTION)
   }
@@ -519,4 +518,10 @@ export abstract class AbstractWorker<
       throw new Error('Performance statistics computation requirements not set')
     }
   }
+
+  private updateLastTaskTimestamp (): void {
+    if (!this.isMain && this.activeInterval != null) {
+      this.lastTaskTimestamp = performance.now()
+    }
+  }
 }