Software /
code /
prosody
Changeset
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 |
parents | 8765:d5ff0982d3e6 |
children | 8767:7738838a013d |
files | util/async.lua |
diffstat | 1 files changed, 16 insertions(+), 0 deletions(-) [+] |
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