diff options
author | Florian Dold <florian@dold.me> | 2022-03-18 15:32:41 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2022-03-21 19:20:48 +0100 |
commit | f8d12f7b0d4af1b1769b89e80c87f9c169678564 (patch) | |
tree | 2478696c7bc1efc6d090b93aa340de542a7dccd9 /packages/taler-wallet-core/src/util/retries.ts | |
parent | 32cd54e11d80bde0274b3c0238f8f5bd00ff83cb (diff) | |
download | wallet-core-f8d12f7b0d4af1b1769b89e80c87f9c169678564.tar.xz |
wallet: t_s/d_us migration
Diffstat (limited to 'packages/taler-wallet-core/src/util/retries.ts')
-rw-r--r-- | packages/taler-wallet-core/src/util/retries.ts | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/packages/taler-wallet-core/src/util/retries.ts b/packages/taler-wallet-core/src/util/retries.ts index 8dec22bed..4b78d38ef 100644 --- a/packages/taler-wallet-core/src/util/retries.ts +++ b/packages/taler-wallet-core/src/util/retries.ts @@ -21,11 +21,11 @@ /** * Imports. */ -import { Timestamp, Duration, getTimestampNow } from "@gnu-taler/taler-util"; +import { AbsoluteTime, Duration } from "@gnu-taler/taler-util"; export interface RetryInfo { - firstTry: Timestamp; - nextRetry: Timestamp; + firstTry: AbsoluteTime; + nextRetry: AbsoluteTime; retryCounter: number; } @@ -45,7 +45,7 @@ export function updateRetryInfoTimeout( r: RetryInfo, p: RetryPolicy = defaultRetryPolicy, ): void { - const now = getTimestampNow(); + const now = AbsoluteTime.now(); if (now.t_ms === "never") { throw Error("assertion failed"); } @@ -54,10 +54,14 @@ export function updateRetryInfoTimeout( return; } - const nextIncrement = p.backoffDelta.d_ms * Math.pow(p.backoffBase, r.retryCounter) + const nextIncrement = + p.backoffDelta.d_ms * Math.pow(p.backoffBase, r.retryCounter); const t = - now.t_ms + (p.maxTimeout.d_ms === "forever" ? nextIncrement : Math.min(p.maxTimeout.d_ms, nextIncrement)); + now.t_ms + + (p.maxTimeout.d_ms === "forever" + ? nextIncrement + : Math.min(p.maxTimeout.d_ms, nextIncrement)); r.nextRetry = { t_ms: t }; } @@ -73,13 +77,13 @@ export function getRetryDuration( return { d_ms: "forever" }; } const t = p.backoffDelta.d_ms * Math.pow(p.backoffBase, r.retryCounter); - return { d_ms: p.maxTimeout.d_ms === "forever" ? t : Math.min(p.maxTimeout.d_ms, t) }; + return { + d_ms: p.maxTimeout.d_ms === "forever" ? t : Math.min(p.maxTimeout.d_ms, t), + }; } -export function initRetryInfo( - p: RetryPolicy = defaultRetryPolicy, -): RetryInfo { - const now = getTimestampNow(); +export function initRetryInfo(p: RetryPolicy = defaultRetryPolicy): RetryInfo { + const now = AbsoluteTime.now(); const info = { firstTry: now, nextRetry: now, |