# HG changeset patch # User Kim Alvefur # Date 1448209109 -3600 # Node ID 58e260832334c4f804d330906d0a715f8bb85d48 # Parent 03bc9e197fcc9a545de08de9ba4a40db06944e63 util.timer: Keep count of how many timer instances are active diff -r 03bc9e197fcc -r 58e260832334 util/timer.lua --- a/util/timer.lua Sun Nov 22 17:00:43 2015 +0100 +++ b/util/timer.lua Sun Nov 22 17:18:29 2015 +0100 @@ -19,6 +19,7 @@ local _add_task = server.add_task; +local _active_timers = 0; local h = indexedbheap.create(); local params = {}; local next_time = nil; @@ -46,6 +47,7 @@ if peek ~= nil then return peek - now; end + _active_timers = _active_timers - 1; end local function add_task(delay, callback, param) local current_time = get_time(); @@ -55,6 +57,7 @@ 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); end return id;