aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2018-03-23 14:02:33 +0000
committerMatthew Wild <mwild1@gmail.com>2018-03-23 14:02:33 +0000
commita8f9a2757f09c1b9c83081034e5ef1106ff47d8d (patch)
tree9a66ab2c432a6f383fc2add6965d4df6d6e38c03 /util
parent5303e726055769fcced5afb1b5ef7eff4b31a704 (diff)
downloadprosody-a8f9a2757f09c1b9c83081034e5ef1106ff47d8d.tar.gz
prosody-a8f9a2757f09c1b9c83081034e5ef1106ff47d8d.zip
util.async: Make parameters to async.runner() optional
Diffstat (limited to 'util')
-rw-r--r--util/async.lua10
1 files changed, 7 insertions, 3 deletions
diff --git a/util/async.lua b/util/async.lua
index f042b177..9456874d 100644
--- a/util/async.lua
+++ b/util/async.lua
@@ -130,10 +130,14 @@ local function runner_create_thread(func, self)
return thread;
end
-local empty_watchers = {};
+local function default_error_watcher(runner, err)
+ runner:log("error", "Encountered error: %s", err);
+ error(err);
+end
+local function default_func(f) f(); end
local function runner(func, watchers, data)
- return setmetatable({ func = func, thread = false, state = "ready", notified_state = "ready",
- queue = {}, watchers = watchers or empty_watchers, data = data, id = new_id() }
+ return setmetatable({ func = func or default_func, thread = false, state = "ready", notified_state = "ready",
+ queue = {}, watchers = watchers or { error = default_error_watcher }, data = data, id = new_id() }
, runner_mt);
end