From: Chris Duncan Date: Wed, 12 Aug 2026 00:25:13 +0000 (-0700) Subject: Revert to simpler vault timer. X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=546a8fc24e70c384cfd10cbdcca094e8648bc840;p=libnemo.git Revert to simpler vault timer. --- diff --git a/src/lib/vault/vault-timer.ts b/src/lib/vault/vault-timer.ts index b596b5c..407953f 100644 --- a/src/lib/vault/vault-timer.ts +++ b/src/lib/vault/vault-timer.ts @@ -8,50 +8,51 @@ */ export class VaultTimer { #f: () => any - #end: PerformanceMark - #start: PerformanceMark + #isPaused: boolean = false + #end: number + #start: number #ticker: number | NodeJS.Timeout #timeout: number | NodeJS.Timeout - get #measureOptions (): PerformanceMeasureOptions { return { start: this.#start.startTime, end: this.#end.startTime } } - get #remaining (): PerformanceMeasure { return performance.measure('vault-timer-remaining', this.#measureOptions) } + get #remaining (): number { return this.#end - this.#start } constructor (f: () => any, t: number) { this.#f = () => { - clearTimeout(this.#timeout) clearInterval(this.#ticker) + clearTimeout(this.#timeout) f() } - this.#start = performance.mark('vault-timer-start') - this.#end = performance.mark('vault-timer-end', { startTime: performance.now() + t }) + this.#start = performance.now() + this.#end = this.#start + t this.#ticker = setInterval(Function.prototype, 1000) - this.#timeout = setTimeout(this.#f, this.#remaining.duration) + this.#timeout = setTimeout(this.#f, this.#remaining) } pause () { - this.#start = performance.mark('vault-timer-paused') - const remaining = this.#remaining.duration - if (remaining > 0) { - clearTimeout(this.#timeout) + if (!this.#isPaused && this.#remaining > 0) { clearInterval(this.#ticker) + clearTimeout(this.#timeout) + this.#start = performance.now() + this.#isPaused = true } } reset (t: number) { clearTimeout(this.#timeout) clearInterval(this.#ticker) - this.#start = performance.mark('vault-timer-start') - this.#end = performance.mark('vault-timer-end', { startTime: performance.now() + t }) + this.#start = performance.now() + this.#end = this.#start + t this.#ticker = setInterval(Function.prototype, 1000) - this.#timeout = setTimeout(this.#f, this.#remaining.duration) + this.#timeout = setTimeout(this.#f, this.#remaining) + this.#isPaused = false } resume () { - const remaining = this.#remaining.duration - if (remaining > 0) { - this.#start = performance.mark('vault-timer-start') - this.#end = performance.mark('vault-timer-end', { startTime: performance.now() + remaining }) - this.#timeout = setTimeout(this.#f, remaining) + if (this.#isPaused && this.#remaining > 0) { + this.#start = performance.now() + this.#ticker = setInterval(Function.prototype, 1000) + this.#timeout = setTimeout(this.#f, this.#remaining) + this.#isPaused = false } } }