Mercurial > prosody-hg
comparison util/timer.lua @ 6931:5c2c8aeb4690
util.timer: Expire timer instance if another instance is already set to take care of the next scheduled event
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sun, 22 Nov 2015 17:20:20 +0100 |
| parents | 58e260832334 |
| children | f5fd2c5cdf28 |
comparison
equal
deleted
inserted
replaced
| 6930:58e260832334 | 6931:5c2c8aeb4690 |
|---|---|
| 41 if success and type(err) == "number" then | 41 if success and type(err) == "number" then |
| 42 h:insert(_callback, err + now, _id); -- re-add | 42 h:insert(_callback, err + now, _id); -- re-add |
| 43 params[_id] = _param; | 43 params[_id] = _param; |
| 44 end | 44 end |
| 45 end | 45 end |
| 46 next_time = peek; | 46 |
| 47 if peek ~= nil then | 47 if peek ~= nil and _active_timers > 1 and peek == next_time then |
| 48 -- Another instance of _on_timer already set next_time to the same value, | |
| 49 -- so it should be safe to not renew this timer event | |
| 50 peek = nil; | |
| 51 else | |
| 52 next_time = peek; | |
| 53 end | |
| 54 | |
| 55 if peek then | |
| 56 -- peek is the time of the next event | |
| 48 return peek - now; | 57 return peek - now; |
| 49 end | 58 end |
| 50 _active_timers = _active_timers - 1; | 59 _active_timers = _active_timers - 1; |
| 51 end | 60 end |
| 52 local function add_task(delay, callback, param) | 61 local function add_task(delay, callback, param) |
