Software /
code /
prosody
Diff
util/async.lua @ 8766:01264bc60c2b
util.async: Add helper methods for setting watchers
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 30 Apr 2018 12:53:53 +0100 |
parent | 8685:2548111e71d6 |
child | 8788:7a9b680a79fb |
line wrap: on
line diff
--- a/util/async.lua Sun Apr 29 22:15:44 2018 +0100 +++ b/util/async.lua Mon Apr 30 12:53:53 2018 +0100 @@ -215,12 +215,28 @@ 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