Software /
code /
prosody
Diff
util/timer.lua @ 9562:acf74ad0b795
Many things: switch from hacky multi-arg xpcall implementations to a standard util.xpcall
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 26 Oct 2018 19:32:00 +0100 |
parent | 8995:2e6f7ab97794 |
child | 10981:e6c1e92cc7a7 |
child | 11263:1274deeab39a |
line wrap: on
line diff
--- a/util/timer.lua Fri Oct 26 19:29:08 2018 +0100 +++ b/util/timer.lua Fri Oct 26 19:32:00 2018 +0100 @@ -13,7 +13,7 @@ local type = type; local debug_traceback = debug.traceback; local tostring = tostring; -local xpcall = xpcall; +local xpcall = require "util.xpcall".xpcall; local math_max = math.max; local _ENV = nil; @@ -26,24 +26,20 @@ local h = indexedbheap.create(); local params = {}; local next_time = nil; -local _id, _callback, _now, _param; -local function _call() return _callback(_now, _id, _param); end local function _traceback_handler(err) log("error", "Traceback[timer]: %s", debug_traceback(tostring(err), 2)); end local function _on_timer(now) local peek; while true do peek = h:peek(); if peek == nil or peek > now then break; end - local _; - _, _callback, _id = h:pop(); - _now = now; - _param = params[_id]; - params[_id] = nil; - --item(now, id, _param); -- FIXME pcall - local success, err = xpcall(_call, _traceback_handler); + local _, callback, id = h:pop(); + local param = params[id]; + params[id] = nil; + --item(now, id, _param); + local success, err = xpcall(callback, _traceback_handler, now, id, param); if success and type(err) == "number" then - h:insert(_callback, err + now, _id); -- re-add - params[_id] = _param; + h:insert(callback, err + now, id); -- re-add + params[id] = param; end end