net.http: Add request.id to every request object (can be overridden by providing...
[prosody.git] / util / watchdog.lua
index 9603141568ea28119d7c4a5946c8af89188e626d..aa8c6486781a51de97f96b4a9c7bf7fd4018b0f0 100644 (file)
@@ -2,12 +2,12 @@ local timer = require "util.timer";
 local setmetatable = setmetatable;
 local os_time = os.time;
 
-module "watchdog"
+local _ENV = nil;
 
 local watchdog_methods = {};
 local watchdog_mt = { __index = watchdog_methods };
 
-function new(timeout, callback)
+local function new(timeout, callback)
        local watchdog = setmetatable({ timeout = timeout, last_reset = os_time(), callback = callback }, watchdog_mt);
        timer.add_task(timeout+1, function (current_time)
                local last_reset = watchdog.last_reset;
@@ -16,7 +16,7 @@ function new(timeout, callback)
                end
                local time_left = (last_reset + timeout) - current_time;
                if time_left < 0 then
-                       return watchdog.callback();
+                       return watchdog:callback();
                end
                return time_left + 1;
        end);
@@ -31,4 +31,6 @@ function watchdog_methods:cancel()
        self.last_reset = nil;
 end
 
-return _M;
+return {
+       new = new;
+};