1 local timer = require "util.timer";
2 local setmetatable = setmetatable;
3 local os_time = os.time;
7 local watchdog_methods = {};
8 local watchdog_mt = { __index = watchdog_methods };
10 function new(timeout, callback)
11 local watchdog = setmetatable({ timeout = timeout, last_reset = os_time(), callback = callback }, watchdog_mt);
12 timer.add_task(timeout+1, function (current_time)
13 local last_reset = watchdog.last_reset;
14 if not last_reset then
17 local time_left = (last_reset + timeout) - current_time;
19 return watchdog:callback();
26 function watchdog_methods:reset()
27 self.last_reset = os_time();
30 function watchdog_methods:cancel()
31 self.last_reset = nil;