aboutsummaryrefslogtreecommitdiffstats
path: root/util/timer.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-01-08 23:56:27 +0100
committerKim Alvefur <zash@zash.se>2021-01-08 23:56:27 +0100
commit2f4d12286f17da4e0a1d6916e9c6addd5f61f9f5 (patch)
treeae3423f96ff891efa62da56d3223f2824ccffd2c /util/timer.lua
parentcb1282bfd0959b52c0725e2249c07c9319b58da0 (diff)
parent365e5b0cb481315525d4f2bfbf478340b8dc08d8 (diff)
downloadprosody-2f4d12286f17da4e0a1d6916e9c6addd5f61f9f5.tar.gz
prosody-2f4d12286f17da4e0a1d6916e9c6addd5f61f9f5.zip
Merge 0.11->trunk
Diffstat (limited to 'util/timer.lua')
-rw-r--r--util/timer.lua15
1 files changed, 14 insertions, 1 deletions
diff --git a/util/timer.lua b/util/timer.lua
index cbfc1992..84da02cf 100644
--- a/util/timer.lua
+++ b/util/timer.lua
@@ -15,6 +15,7 @@ local debug_traceback = debug.traceback;
local tostring = tostring;
local xpcall = require "util.xpcall".xpcall;
local math_max = math.max;
+local pairs = pairs;
if server.timer then
-- The selected net.server implements this API, so defer to that
@@ -34,6 +35,7 @@ local next_time = nil;
local function _traceback_handler(err) log("error", "Traceback[timer]: %s", debug_traceback(tostring(err), 2)); end
local function _on_timer(now)
local peek;
+ local readd;
while true do
peek = h:peek();
if peek == nil or peek > now then break; end
@@ -43,11 +45,22 @@ local function _on_timer(now)
--item(now, id, _param);
local success, err = xpcall(callback, _traceback_handler, now, id, param);
if success and type(err) == "number" then
- h:insert(callback, err + now, id); -- re-add
+ if readd then
+ readd[id] = { callback, err + now };
+ else
+ readd = { [id] = { callback, err + now } };
+ end
params[id] = param;
end
end
+ if readd then
+ for id,timer in pairs(readd) do
+ h:insert(timer[1], timer[2], id);
+ end
+ peek = h:peek();
+ end
+
if peek ~= nil and _active_timers > 1 and peek == next_time then
-- Another instance of _on_timer already set next_time to the same value,
-- so it should be safe to not renew this timer event