diff options
author | Kim Alvefur <zash@zash.se> | 2015-11-22 17:25:44 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2015-11-22 17:25:44 +0100 |
commit | 628bbf628ab168f06c405f89b4b7fb084102a862 (patch) | |
tree | 8a4d3f66b262d3a634df630f51e999a126fc1070 | |
parent | 13c5628054e17a8f7f2402e81e8198ab52558dea (diff) | |
download | prosody-628bbf628ab168f06c405f89b4b7fb084102a862.tar.gz prosody-628bbf628ab168f06c405f89b4b7fb084102a862.zip |
util.timer: If possible, close the existing timer handle in order to have only one
-rw-r--r-- | util/timer.lua | 10 |
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 |