Software /
code /
prosody
Comparison
util/timer.lua @ 8762:2f8523bf7ff2
util.timer: Ensure we don't try to schedule negative timeouts (which rightly upset libevent). Fixes #1135
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 29 Apr 2018 21:43:39 +0100 |
parent | 8685:2548111e71d6 |
child | 8995:2e6f7ab97794 |
comparison
equal
deleted
inserted
replaced
8761:b6e193e33145 | 8762:2f8523bf7ff2 |
---|---|
13 local async = require "util.async"; | 13 local async = require "util.async"; |
14 local type = type; | 14 local type = type; |
15 local debug_traceback = debug.traceback; | 15 local debug_traceback = debug.traceback; |
16 local tostring = tostring; | 16 local tostring = tostring; |
17 local xpcall = xpcall; | 17 local xpcall = xpcall; |
18 local math_max = math.max; | |
18 | 19 |
19 local _ENV = nil; | 20 local _ENV = nil; |
20 -- luacheck: std none | 21 -- luacheck: std none |
21 | 22 |
22 local _add_task = server.add_task; | 23 local _add_task = server.add_task; |
85 local peek = h:peek(); | 86 local peek = h:peek(); |
86 if peek ~= next_time and _server_timer then | 87 if peek ~= next_time and _server_timer then |
87 next_time = peek; | 88 next_time = peek; |
88 _server_timer:close(); | 89 _server_timer:close(); |
89 if next_time ~= nil then | 90 if next_time ~= nil then |
90 _server_timer = _add_task(next_time - get_time(), _on_timer); | 91 _server_timer = _add_task(math_max(next_time - get_time(), 0), _on_timer); |
91 end | 92 end |
92 end | 93 end |
93 return result, item, result_sync; | 94 return result, item, result_sync; |
94 end | 95 end |
95 local function reschedule(id, delay) | 96 local function reschedule(id, delay) |