From 13c5628054e17a8f7f2402e81e8198ab52558dea Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 22 Nov 2015 17:20:20 +0100 Subject: util.timer: Expire timer instance if another instance is already set to take care of the next scheduled event --- util/timer.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'util') diff --git a/util/timer.lua b/util/timer.lua index 9042264d..78b4dbd7 100644 --- a/util/timer.lua +++ b/util/timer.lua @@ -43,8 +43,17 @@ local function _on_timer(now) params[_id] = _param; end end - next_time = peek; - if peek ~= nil then + + if peek ~= nil and _active_timers > 1 and peek == next_time then + -- Another instance of _on_timer already set next_time to the same value, + -- so it should be safe to not renew this timer event + peek = nil; + else + next_time = peek; + end + + if peek then + -- peek is the time of the next event return peek - now; end _active_timers = _active_timers - 1; -- cgit v1.2.3