# HG changeset patch # User Matthew Wild # Date 1654982114 -3600 # Node ID e78b35574aaebfc08063d40c784b1306cefb6bb1 # Parent 5059a639f61ec7590ebfd29cac18b5ad13b335e2 util.watchdog: Allow :reset() to restart a cancelled watchdog diff -r 5059a639f61e -r e78b35574aae util/watchdog.lua --- a/util/watchdog.lua Sat Jun 11 21:11:01 2022 +0100 +++ b/util/watchdog.lua Sat Jun 11 22:15:14 2022 +0100 @@ -1,6 +1,5 @@ local timer = require "util.timer"; local setmetatable = setmetatable; -local os_time = os.time; local _ENV = nil; -- luacheck: std none @@ -15,16 +14,18 @@ timer_id = nil; }, watchdog_mt); - watchdog.timer_id = timer.add_task(timeout+1, function () - return watchdog:callback(); - end); + watchdog:reset(); -- Kick things off return watchdog; end function watchdog_methods:reset() if self.timer_id then - timer.reschedule(self.timer_id, self.timeout); + timer.reschedule(self.timer_id, self.timeout+1); + else + self.timer_id = timer.add_task(self.timeout+1, function () + return self:callback(); + end); end end