aboutsummaryrefslogtreecommitdiffstats
path: root/util/async.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2018-04-30 12:53:53 +0100
committerMatthew Wild <mwild1@gmail.com>2018-04-30 12:53:53 +0100
commit289bb74872451c25af847b4719165d3ae6d89372 (patch)
tree39aac646bbf509a67a34694a84046c4551afc4f7 /util/async.lua
parentee0ca565fe4ff41c43cc9cd2264be2ba8077303f (diff)
downloadprosody-289bb74872451c25af847b4719165d3ae6d89372.tar.gz
prosody-289bb74872451c25af847b4719165d3ae6d89372.zip
util.async: Add helper methods for setting watchers
Diffstat (limited to 'util/async.lua')
-rw-r--r--util/async.lua16
1 files changed, 16 insertions, 0 deletions
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