Software /
code /
prosody
Comparison
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 |
comparison
equal
deleted
inserted
replaced
8765:d5ff0982d3e6 | 8766:01264bc60c2b |
---|---|
213 | 213 |
214 -- Add a task item to the queue without invoking the runner, even if it is idle | 214 -- Add a task item to the queue without invoking the runner, even if it is idle |
215 function runner_mt:enqueue(input) | 215 function runner_mt:enqueue(input) |
216 table.insert(self.queue, input); | 216 table.insert(self.queue, input); |
217 self:log("debug", "queued new work item, %d items queued", #self.queue); | 217 self:log("debug", "queued new work item, %d items queued", #self.queue); |
218 return self; | |
218 end | 219 end |
219 | 220 |
220 function runner_mt:log(level, fmt, ...) | 221 function runner_mt:log(level, fmt, ...) |
221 return log(level, "[runner %s] "..fmt, self.id, ...); | 222 return log(level, "[runner %s] "..fmt, self.id, ...); |
223 end | |
224 | |
225 function runner_mt:onready(f) | |
226 self.watchers.ready = f; | |
227 return self; | |
228 end | |
229 | |
230 function runner_mt:onwaiting(f) | |
231 self.watchers.waiting = f; | |
232 return self; | |
233 end | |
234 | |
235 function runner_mt:onerror(f) | |
236 self.watchers.error = f; | |
237 return self; | |
222 end | 238 end |
223 | 239 |
224 local function ready() | 240 local function ready() |
225 return pcall(checkthread); | 241 return pcall(checkthread); |
226 end | 242 end |