summaryrefslogtreecommitdiff
path: root/ui/lib/watchdog.js
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2025-04-10 20:50:13 -0400
committerOwen Jacobson <owen@grimoire.ca>2025-04-10 20:50:13 -0400
commit1ef57107b1c355ef896327f0714344277df7ae18 (patch)
tree9874d3d61f0bdb13913c6c4d079fbb82b336f656 /ui/lib/watchdog.js
parent0fc3057b05dddb4eba142deeb6373ed37e312c60 (diff)
parent1ee129176eb71f5e246462b66fd9c9862ed1ee7a (diff)
Use a heartbeat to allow the client to reconnect after network failures.
Diffstat (limited to 'ui/lib/watchdog.js')
-rw-r--r--ui/lib/watchdog.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/ui/lib/watchdog.js b/ui/lib/watchdog.js
new file mode 100644
index 0000000..c95fd4d
--- /dev/null
+++ b/ui/lib/watchdog.js
@@ -0,0 +1,27 @@
+export class Watchdog {
+ constructor(onExpired) {
+ this.timeout = null;
+ this.onExpired = onExpired;
+ }
+
+ reset(delay) {
+ if (this.timeout !== null) {
+ clearTimeout(this.timeout);
+ }
+ this.timeout = setTimeout(this.expire.bind(this), delay);
+ }
+
+ stop() {
+ if (this.timeout !== null) {
+ clearTimeout(this.timeout);
+ this.timeout = null;
+ }
+ }
+
+ expire() {
+ if (this.timeout !== null) {
+ this.timeout = null;
+ }
+ this.onExpired();
+ }
+}