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