Comparison

util/timer.lua @ 842:4932f94d35c1

util.timer: More small fixes I forgot to commit
author Matthew Wild <mwild1@gmail.com>
date Thu, 26 Feb 2009 22:17:55 +0000
parent 841:77ff000c2055
child 896:2c0b9e3c11c3
comparison
equal deleted inserted replaced
841:77ff000c2055 842:4932f94d35c1
30 add_task = _add_task; 30 add_task = _add_task;
31 31
32 ns_addtimer(function() 32 ns_addtimer(function()
33 local current_time = get_time(); 33 local current_time = get_time();
34 if #new_data > 0 then 34 if #new_data > 0 then
35 for _, d in ipairs(new_data) do 35 for _, d in pairs(new_data) do
36 t_insert(data, d); 36 t_insert(data, d);
37 end 37 end
38 new_data = {}; 38 new_data = {};
39 elseif #data == 0 then
40 return;
41 end 39 end
42 40
43 for i, d in pairs(data) do 41 for i, d in pairs(data) do
44 local t, func = d[1], d[2]; 42 local t, func = d[1], d[2];
45 if t <= current_time then 43 if t <= current_time then
46 t_remove(data, i); 44 data[i] = nil;
47 local r = func(); 45 local r = func();
48 if type(r) == "number" then _add_task(r, func); end 46 if type(r) == "number" then _add_task(r, func); end
49 end 47 end
50 end 48 end
51 end); 49 end);