Software /
code /
prosody
Comparison
util/timer.lua @ 4871:b2d177f2febc
util.timer: Always pass the current time to timer callbacks.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sat, 12 May 2012 21:46:54 +0500 |
parent | 4812:5bcdc384e485 |
child | 5776:bd0ff8ae98a8 |
comparison
equal
deleted
inserted
replaced
4870:ca39f9b4cc8e | 4871:b2d177f2febc |
---|---|
25 local current_time = get_time(); | 25 local current_time = get_time(); |
26 delay = delay + current_time; | 26 delay = delay + current_time; |
27 if delay >= current_time then | 27 if delay >= current_time then |
28 t_insert(new_data, {delay, callback}); | 28 t_insert(new_data, {delay, callback}); |
29 else | 29 else |
30 local r = callback(); | 30 local r = callback(current_time); |
31 if r and type(r) == "number" then | 31 if r and type(r) == "number" then |
32 return _add_task(r, callback); | 32 return _add_task(r, callback); |
33 end | 33 end |
34 end | 34 end |
35 end | 35 end |
65 local EVENT_LEAVE = (event.core and event.core.LEAVE) or -1; | 65 local EVENT_LEAVE = (event.core and event.core.LEAVE) or -1; |
66 | 66 |
67 function _add_task(delay, callback) | 67 function _add_task(delay, callback) |
68 local event_handle; | 68 local event_handle; |
69 event_handle = event_base:addevent(nil, 0, function () | 69 event_handle = event_base:addevent(nil, 0, function () |
70 local ret = callback(); | 70 local ret = callback(get_time()); |
71 if ret then | 71 if ret then |
72 return 0, ret; | 72 return 0, ret; |
73 elseif event_handle then | 73 elseif event_handle then |
74 return EVENT_LEAVE; | 74 return EVENT_LEAVE; |
75 end | 75 end |