From eb96155cf38e4265efef76c70027d684dad2e9f0 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 30 Apr 2018 12:53:53 +0100 Subject: util.async: Add helper methods for setting watchers --- util/async.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'util') diff --git a/util/async.lua b/util/async.lua index 012cfd87..e8be0510 100644 --- a/util/async.lua +++ b/util/async.lua @@ -215,12 +215,28 @@ end function runner_mt:enqueue(input) table.insert(self.queue, input); self:log("debug", "queued new work item, %d items queued", #self.queue); + return self; end function runner_mt:log(level, fmt, ...) return log(level, "[runner %s] "..fmt, self.id, ...); end +function runner_mt:onready(f) + self.watchers.ready = f; + return self; +end + +function runner_mt:onwaiting(f) + self.watchers.waiting = f; + return self; +end + +function runner_mt:onerror(f) + self.watchers.error = f; + return self; +end + local function ready() return pcall(checkthread); end -- cgit v1.2.3