aboutsummaryrefslogtreecommitdiffstats
path: root/util/timer.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2015-11-22 17:25:44 +0100
committerKim Alvefur <zash@zash.se>2015-11-22 17:25:44 +0100
commit628bbf628ab168f06c405f89b4b7fb084102a862 (patch)
tree8a4d3f66b262d3a634df630f51e999a126fc1070 /util/timer.lua
parent13c5628054e17a8f7f2402e81e8198ab52558dea (diff)
downloadprosody-628bbf628ab168f06c405f89b4b7fb084102a862.tar.gz
prosody-628bbf628ab168f06c405f89b4b7fb084102a862.zip
util.timer: If possible, close the existing timer handle in order to have only one
Diffstat (limited to 'util/timer.lua')
-rw-r--r--util/timer.lua10
1 files changed, 8 insertions, 2 deletions
diff --git a/util/timer.lua b/util/timer.lua
index 78b4dbd7..eb2bd7ea 100644
--- a/util/timer.lua
+++ b/util/timer.lua
@@ -19,6 +19,7 @@ local _ENV = nil;
local _add_task = server.add_task;
+local _server_timer;
local _active_timers = 0;
local h = indexedbheap.create();
local params = {};
@@ -66,8 +67,13 @@ local function add_task(delay, callback, param)
params[id] = param;
if next_time == nil or event_time < next_time then
next_time = event_time;
- _active_timers = _active_timers + 1;
- _add_task(next_time - current_time, _on_timer);
+ if _server_timer then
+ _server_timer:close();
+ _server_timer = nil;
+ else
+ _active_timers = _active_timers + 1;
+ end
+ _server_timer = _add_task(next_time - current_time, _on_timer);
end
return id;
end