From: Jérôme Benoit Date: Mon, 17 Jul 2023 13:27:51 +0000 (+0200) Subject: refactor: factor out last task timestamp update X-Git-Tag: v2.6.18~13 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=c3f498b53e1effc6021058c6795dacc537797121;p=poolifier.git refactor: factor out last task timestamp update Signed-off-by: Jérôme Benoit --- 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() + } + } }