Diff

util/timer.lua @ 6930:58e260832334

util.timer: Keep count of how many timer instances are active
author Kim Alvefur <zash@zash.se>
date Sun, 22 Nov 2015 17:18:29 +0100
parent 6836:9f45f0fe5aef
child 6931:5c2c8aeb4690
line wrap: on
line diff
--- 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;