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(); } }