From 82a2437c0967871d6b942105c98c3382978cad29 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 6 Aug 2020 00:30:36 +0530 Subject: towards integration tests with fault injection --- packages/taler-wallet-core/src/util/timer.ts | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'packages/taler-wallet-core/src/util/timer.ts') 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(); + } }; } } -- cgit v1.2.3