From c3f498b53e1effc6021058c6795dacc537797121 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 17 Jul 2023 15:27:51 +0200 Subject: [PATCH] refactor: factor out last task timestamp update MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/worker/abstract-worker.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index 7d5494de..2f4212f9 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -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() + } + } } -- 2.34.1