Software / code / prosody
Comparison
util/async.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 | 9177:83e7ad5818d3 |
| child | 10291:7b48b620164c |
comparison
equal
deleted
inserted
replaced
| 9561:cfc7b2f7251e | 9562:acf74ad0b795 |
|---|---|
| 1 local logger = require "util.logger"; | 1 local logger = require "util.logger"; |
| 2 local log = logger.init("util.async"); | 2 local log = logger.init("util.async"); |
| 3 local new_id = require "util.id".short; | 3 local new_id = require "util.id".short; |
| 4 local xpcall = require "util.xpcall".xpcall; | |
| 4 | 5 |
| 5 local function checkthread() | 6 local function checkthread() |
| 6 local thread, main = coroutine.running(); | 7 local thread, main = coroutine.running(); |
| 7 if not thread or main then | 8 if not thread or main then |
| 8 error("Not running in an async context, see https://prosody.im/doc/developers/util/async"); | 9 error("Not running in an async context, see https://prosody.im/doc/developers/util/async"); |
| 25 local watcher = runner.watchers[watcher_name]; | 26 local watcher = runner.watchers[watcher_name]; |
| 26 if not watcher then | 27 if not watcher then |
| 27 return false; | 28 return false; |
| 28 end | 29 end |
| 29 runner:log("debug", "Calling '%s' watcher", watcher_name); | 30 runner:log("debug", "Calling '%s' watcher", watcher_name); |
| 30 local ok, err = pcall(watcher, runner, ...); -- COMPAT: Switch to xpcall after Lua 5.1 | 31 local ok, err = xpcall(watcher, debug.traceback, runner, ...); |
| 31 if not ok then | 32 if not ok then |
| 32 runner:log("error", "Error in '%s' watcher: %s", watcher_name, err); | 33 runner:log("error", "Error in '%s' watcher: %s", watcher_name, err); |
| 33 return nil, err; | 34 return nil, err; |
| 34 end | 35 end |
| 35 return true; | 36 return true; |