From a8f9a2757f09c1b9c83081034e5ef1106ff47d8d Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 23 Mar 2018 14:02:33 +0000 Subject: util.async: Make parameters to async.runner() optional --- util/async.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'util/async.lua') 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 -- cgit v1.2.3