Software /
code /
prosody
Comparison
util/watchdog.lua @ 6777:5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 21 Feb 2015 10:36:37 +0100 |
parent | 4891:189cfe565d03 |
child | 8555:4f0f5b49bb03 |
comparison
equal
deleted
inserted
replaced
6774:3965662ae091 | 6777:5de6b93d0190 |
---|---|
1 local timer = require "util.timer"; | 1 local timer = require "util.timer"; |
2 local setmetatable = setmetatable; | 2 local setmetatable = setmetatable; |
3 local os_time = os.time; | 3 local os_time = os.time; |
4 | 4 |
5 module "watchdog" | 5 local _ENV = nil; |
6 | 6 |
7 local watchdog_methods = {}; | 7 local watchdog_methods = {}; |
8 local watchdog_mt = { __index = watchdog_methods }; | 8 local watchdog_mt = { __index = watchdog_methods }; |
9 | 9 |
10 function new(timeout, callback) | 10 local function new(timeout, callback) |
11 local watchdog = setmetatable({ timeout = timeout, last_reset = os_time(), callback = callback }, watchdog_mt); | 11 local watchdog = setmetatable({ timeout = timeout, last_reset = os_time(), callback = callback }, watchdog_mt); |
12 timer.add_task(timeout+1, function (current_time) | 12 timer.add_task(timeout+1, function (current_time) |
13 local last_reset = watchdog.last_reset; | 13 local last_reset = watchdog.last_reset; |
14 if not last_reset then | 14 if not last_reset then |
15 return; | 15 return; |
29 | 29 |
30 function watchdog_methods:cancel() | 30 function watchdog_methods:cancel() |
31 self.last_reset = nil; | 31 self.last_reset = nil; |
32 end | 32 end |
33 | 33 |
34 return _M; | 34 return { |
35 new = new; | |
36 }; |