Comparison

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
comparison
equal deleted inserted replaced
7014:298bfc768889 7015:17e275e8bd79
77 end 77 end
78 return id; 78 return id;
79 end 79 end
80 local function stop(id) 80 local function stop(id)
81 params[id] = nil; 81 params[id] = nil;
82 return h:remove(id); 82 local result, item, result_sync = h:remove(id);
83 local peek = h:peek();
84 if peek ~= next_time and _server_timer then
85 next_time = peek;
86 _server_timer:close();
87 if next_time ~= nil then
88 _server_timer = _add_task(next_time - get_time(), _on_timer);
89 end
90 end
91 return result, item, result_sync;
83 end 92 end
84 local function reschedule(id, delay) 93 local function reschedule(id, delay)
85 local current_time = get_time(); 94 local current_time = get_time();
86 local event_time = current_time + delay; 95 local event_time = current_time + delay;
87 h:reprioritize(id, delay); 96 h:reprioritize(id, delay);