Software /
code /
prosody
Comparison
net/server_epoll.lua @ 10982:276f16101d59
net.server_epoll: Make API-compatible with util.timer
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 29 Jun 2020 16:42:16 +0200 |
parent | 10861:e12690a37795 |
child | 10983:0862325842ec |
comparison
equal
deleted
inserted
replaced
10981:e6c1e92cc7a7 | 10982:276f16101d59 |
---|---|
97 t[1] = time; | 97 t[1] = time; |
98 timers:reprioritize(t.id, time); | 98 timers:reprioritize(t.id, time); |
99 end | 99 end |
100 | 100 |
101 -- Add relative timer | 101 -- Add relative timer |
102 local function addtimer(timeout, f) | 102 local function addtimer(timeout, f, param) |
103 local time = monotonic() + timeout; | 103 local time = monotonic() + timeout; |
104 local timer = { time, f, close = closetimer, reschedule = reschedule, id = nil }; | 104 local timer = { time, f, param, close = closetimer, reschedule = reschedule, id = nil }; |
105 timer.id = timers:insert(timer, time); | 105 timer.id = timers:insert(timer, time); |
106 return timer; | 106 return timer; |
107 end | 107 end |
108 | 108 |
109 -- Run callbacks of expired timers | 109 -- Run callbacks of expired timers |
119 next_delay = peek - elapsed; | 119 next_delay = peek - elapsed; |
120 break; | 120 break; |
121 end | 121 end |
122 | 122 |
123 local _, timer = timers:pop(); | 123 local _, timer = timers:pop(); |
124 local ok, ret = pcall(timer[2], now); | 124 local ok, ret = pcall(timer[2], now, timer, timer[3]); |
125 if ok and type(ret) == "number" then | 125 if ok and type(ret) == "number" then |
126 local next_time = elapsed+ret; | 126 local next_time = elapsed+ret; |
127 timer[1] = next_time; | 127 timer[1] = next_time; |
128 timers:insert(timer, next_time); | 128 timers:insert(timer, next_time); |
129 end | 129 end |