Comparison

util/timer.lua @ 2964:49b5c87d2fa0

util.timer: When using libevent hold onto the event handle to stop it being collected (and the timer stopping). Fixes BOSH ghosts, thanks Flo, niekie, waqas.
author Matthew Wild <mwild1@gmail.com>
date Wed, 07 Apr 2010 21:00:20 +0100
parent 2925:692b3c6c5bd2
child 3683:c2158221e2e6
comparison
equal deleted inserted replaced
2961:db3c0ecce3f4 2964:49b5c87d2fa0
53 end 53 end
54 end); 54 end);
55 else 55 else
56 local EVENT_LEAVE = (event.core and event.core.LEAVE) or -1; 56 local EVENT_LEAVE = (event.core and event.core.LEAVE) or -1;
57 function _add_task(delay, func) 57 function _add_task(delay, func)
58 event_base:addevent(nil, 0, function () 58 local event_handle;
59 event_handle = event_base:addevent(nil, 0, function ()
59 local ret = func(); 60 local ret = func();
60 if ret then 61 if ret then
61 return 0, ret; 62 return 0, ret;
62 else 63 elseif event_handle then
63 return EVENT_LEAVE; 64 return EVENT_LEAVE;
64 end 65 end
65 end 66 end
66 , delay); 67 , delay);
67 end 68 end