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 | 669071d1f3851308d80fb84af77f564c3dd0e034 (patch) | |
tree | 8a4d3f66b262d3a634df630f51e999a126fc1070 /util | |
parent | 3df8a52d197a8fb2c51761950d8be7012ddd6141 (diff) | |
download | prosody-669071d1f3851308d80fb84af77f564c3dd0e034.tar.gz prosody-669071d1f3851308d80fb84af77f564c3dd0e034.zip |
util.timer: If possible, close the existing timer handle in order to have only one
Diffstat (limited to 'util')
-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 |