Software /
code /
prosody
Comparison
util/timer.lua @ 6836:9f45f0fe5aef
util.timer: Fix indentation
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 18 Sep 2015 16:08:35 +0200 |
parent | 6791:e813e8cf6046 |
child | 6930:58e260832334 |
comparison
equal
deleted
inserted
replaced
6835:3afb8aa78069 | 6836:9f45f0fe5aef |
---|---|
38 --item(now, id, _param); -- FIXME pcall | 38 --item(now, id, _param); -- FIXME pcall |
39 local success, err = xpcall(_call, _traceback_handler); | 39 local success, err = xpcall(_call, _traceback_handler); |
40 if success and type(err) == "number" then | 40 if success and type(err) == "number" then |
41 h:insert(_callback, err + now, _id); -- re-add | 41 h:insert(_callback, err + now, _id); -- re-add |
42 params[_id] = _param; | 42 params[_id] = _param; |
43 end | |
44 end | 43 end |
44 end | |
45 next_time = peek; | 45 next_time = peek; |
46 if peek ~= nil then | 46 if peek ~= nil then |
47 return peek - now; | 47 return peek - now; |
48 end | 48 end |
49 end | 49 end |
50 local function add_task(delay, callback, param) | 50 local function add_task(delay, callback, param) |
51 local current_time = get_time(); | 51 local current_time = get_time(); |
52 local event_time = current_time + delay; | 52 local event_time = current_time + delay; |
53 | 53 |
54 local id = h:insert(callback, event_time); | 54 local id = h:insert(callback, event_time); |
55 params[id] = param; | 55 params[id] = param; |
56 if next_time == nil or event_time < next_time then | 56 if next_time == nil or event_time < next_time then |
57 next_time = event_time; | 57 next_time = event_time; |
58 _add_task(next_time - current_time, _on_timer); | 58 _add_task(next_time - current_time, _on_timer); |
59 end | 59 end |
60 return id; | 60 return id; |
61 end | 61 end |
62 local function stop(id) | 62 local function stop(id) |
63 params[id] = nil; | 63 params[id] = nil; |
64 return h:remove(id); | 64 return h:remove(id); |
65 end | 65 end |
66 local function reschedule(id, delay) | 66 local function reschedule(id, delay) |
67 local current_time = get_time(); | 67 local current_time = get_time(); |
68 local event_time = current_time + delay; | 68 local event_time = current_time + delay; |
69 h:reprioritize(id, delay); | 69 h:reprioritize(id, delay); |
70 if next_time == nil or event_time < next_time then | 70 if next_time == nil or event_time < next_time then |
71 next_time = event_time; | 71 next_time = event_time; |
72 _add_task(next_time - current_time, _on_timer); | 72 _add_task(next_time - current_time, _on_timer); |
73 end | 73 end |
74 return id; | 74 return id; |
75 end | 75 end |
76 | 76 |
77 return { | 77 return { |
78 add_task = add_task; | 78 add_task = add_task; |