aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-util/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-util/src')
-rw-r--r--packages/taler-util/src/time.ts23
-rw-r--r--packages/taler-util/src/wallet-types.ts12
2 files changed, 32 insertions, 3 deletions
diff --git a/packages/taler-util/src/time.ts b/packages/taler-util/src/time.ts
index c677d52ae..5702b2947 100644
--- a/packages/taler-util/src/time.ts
+++ b/packages/taler-util/src/time.ts
@@ -21,7 +21,7 @@
/**
* Imports.
*/
-import { Codec, renderContext, Context } from "./codec.js";
+import { Codec, Context, renderContext } from "./codec.js";
declare const flavor_AbsoluteTime: unique symbol;
declare const flavor_TalerProtocolTimestamp: unique symbol;
@@ -412,6 +412,10 @@ export namespace AbsoluteTime {
return cmp(t, now()) <= 0;
}
+ export function isNever(t: AbsoluteTime): boolean {
+ return t.t_ms === "never";
+ }
+
export function fromProtocolTimestamp(
t: TalerProtocolTimestamp,
): AbsoluteTime {
@@ -503,6 +507,23 @@ export namespace AbsoluteTime {
return { t_ms: t1.t_ms + d.d_ms, [opaque_AbsoluteTime]: true };
}
+ /**
+ * Get the remaining duration until {@param t1}.
+ *
+ * If {@param t1} already happened, the remaining duration
+ * is zero.
+ */
+ export function remaining(t1: AbsoluteTime): Duration {
+ if (t1.t_ms === "never") {
+ return Duration.getForever();
+ }
+ const stampNow = now();
+ if (stampNow.t_ms === "never") {
+ throw Error("invariant violated");
+ }
+ return Duration.fromMilliseconds(Math.max(0, t1.t_ms - stampNow.t_ms));
+ }
+
export function subtractDuraction(
t1: AbsoluteTime,
d: Duration,
diff --git a/packages/taler-util/src/wallet-types.ts b/packages/taler-util/src/wallet-types.ts
index 0749df9f9..b79bfe4fe 100644
--- a/packages/taler-util/src/wallet-types.ts
+++ b/packages/taler-util/src/wallet-types.ts
@@ -71,12 +71,10 @@ import {
} from "./taler-types.js";
import {
AbsoluteTime,
- Duration,
TalerPreciseTimestamp,
TalerProtocolDuration,
TalerProtocolTimestamp,
codecForAbsoluteTime,
- codecForDuration,
codecForTimestamp,
} from "./time.js";
import {
@@ -3062,3 +3060,13 @@ export const codecForRemoveGlobalCurrencyAuditorRequest =
.property("auditorBaseUrl", codecForString())
.property("auditorPub", codecForString())
.build("RemoveGlobalCurrencyAuditorRequest");
+
+export interface RetryLoopOpts {
+ /**
+ * Stop the retry loop when all lifeness-giving pending operations
+ * are done.
+ *
+ * Defaults to false.
+ */
+ stopWhenDone?: boolean;
+}