Software /
code /
prosody
Diff
util/timer.lua @ 7015:17e275e8bd79
util.timer: Reschedule timers from stop() if the next pending event is stopped
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 23 Dec 2015 11:43:39 +0100 |
parent | 6932:f5fd2c5cdf28 |
child | 7989:5632aa85e0b6 |
line wrap: on
line diff
--- a/util/timer.lua Wed Dec 23 11:42:14 2015 +0100 +++ b/util/timer.lua Wed Dec 23 11:43:39 2015 +0100 @@ -79,7 +79,16 @@ end local function stop(id) params[id] = nil; - return h:remove(id); + local result, item, result_sync = h:remove(id); + local peek = h:peek(); + if peek ~= next_time and _server_timer then + next_time = peek; + _server_timer:close(); + if next_time ~= nil then + _server_timer = _add_task(next_time - get_time(), _on_timer); + end + end + return result, item, result_sync; end local function reschedule(id, delay) local current_time = get_time();