summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/util/timer.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-core/src/util/timer.ts')
-rw-r--r--packages/taler-wallet-core/src/util/timer.ts36
1 files changed, 36 insertions, 0 deletions
diff --git a/packages/taler-wallet-core/src/util/timer.ts b/packages/taler-wallet-core/src/util/timer.ts
index 8eab1399c..d652fdcda 100644
--- a/packages/taler-wallet-core/src/util/timer.ts
+++ b/packages/taler-wallet-core/src/util/timer.ts
@@ -34,6 +34,12 @@ const logger = new Logger("timer.ts");
*/
export interface TimerHandle {
clear(): void;
+
+ /**
+ * Make sure the event loop exits when the timer is the
+ * only event left. Has no effect in the browser.
+ */
+ unref(): void;
}
class IntervalHandle {
@@ -42,6 +48,16 @@ class IntervalHandle {
clear(): void {
clearInterval(this.h);
}
+
+ /**
+ * Make sure the event loop exits when the timer is the
+ * only event left. Has no effect in the browser.
+ */
+ unref(): void {
+ if (typeof this.h === "object") {
+ this.h.unref();
+ }
+ }
}
class TimeoutHandle {
@@ -50,6 +66,16 @@ class TimeoutHandle {
clear(): void {
clearTimeout(this.h);
}
+
+ /**
+ * Make sure the event loop exits when the timer is the
+ * only event left. Has no effect in the browser.
+ */
+ unref(): void {
+ if (typeof this.h === "object") {
+ this.h.unref();
+ }
+ }
}
/**
@@ -92,6 +118,10 @@ const nullTimerHandle = {
// do nothing
return;
},
+ unref() {
+ // do nothing
+ return;
+ }
};
/**
@@ -141,6 +171,9 @@ export class TimerGroup {
h.clear();
delete tm[myId];
},
+ unref() {
+ h.unref();
+ }
};
}
@@ -160,6 +193,9 @@ export class TimerGroup {
h.clear();
delete tm[myId];
},
+ unref() {
+ h.unref();
+ }
};
}
}