Merge 0.9->0.10
[prosody.git] / util / timer.lua
index ba7dd4291073cf4754aac4d3f885a43037b17cda..3713625db3d6cbcb3d2c78fe5ff79c95aff13b79 100644 (file)
@@ -1,7 +1,7 @@
 -- Prosody IM
 -- Copyright (C) 2008-2010 Matthew Wild
 -- Copyright (C) 2008-2010 Waqas Hussain
--- 
+--
 -- This project is MIT/X11 licensed. Please see the
 -- COPYING file in the source package for more information.
 --
@@ -17,7 +17,7 @@ local type = type;
 local data = {};
 local new_data = {};
 
-module "timer"
+local _ENV = nil;
 
 local _add_task;
 if not server.event then
@@ -27,7 +27,7 @@ if not server.event then
                if delay >= current_time then
                        t_insert(new_data, {delay, callback});
                else
-                       local r = callback();
+                       local r = callback(current_time);
                        if r and type(r) == "number" then
                                return _add_task(r, callback);
                        end
@@ -42,7 +42,7 @@ if not server.event then
                        end
                        new_data = {};
                end
-               
+
                local next_time = math_huge;
                for i, d in pairs(data) do
                        local t, callback = d[1], d[2];
@@ -60,14 +60,14 @@ if not server.event then
                return next_time;
        end);
 else
-       local event = require "net.server".event;
-       local event_base = require "net.server".event_base;
+       local event = server.event;
+       local event_base = server.event_base;
        local EVENT_LEAVE = (event.core and event.core.LEAVE) or -1;
 
        function _add_task(delay, callback)
                local event_handle;
                event_handle = event_base:addevent(nil, 0, function ()
-                       local ret = callback();
+                       local ret = callback(get_time());
                        if ret then
                                return 0, ret;
                        elseif event_handle then
@@ -78,6 +78,6 @@ else
        end
 end
 
-add_task = _add_task;
-
-return _M;
+return {
+       add_task = _add_task;
+};