Software / code / prosody
Comparison
util/async.lua @ 8681:0c077800cd70
util.async: Make parameters to async.runner() optional
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Fri, 23 Mar 2018 14:02:33 +0000 |
| parent | 8669:2aa85b0cd2b8 |
| child | 8683:867ac771fb6e |
comparison
equal
deleted
inserted
replaced
| 8680:1cc9a293e958 | 8681:0c077800cd70 |
|---|---|
| 128 end); | 128 end); |
| 129 assert(coroutine.resume(thread, self)); -- Start it up, it will return instantly to wait for the first input | 129 assert(coroutine.resume(thread, self)); -- Start it up, it will return instantly to wait for the first input |
| 130 return thread; | 130 return thread; |
| 131 end | 131 end |
| 132 | 132 |
| 133 local empty_watchers = {}; | 133 local function default_error_watcher(runner, err) |
| 134 runner:log("error", "Encountered error: %s", err); | |
| 135 error(err); | |
| 136 end | |
| 137 local function default_func(f) f(); end | |
| 134 local function runner(func, watchers, data) | 138 local function runner(func, watchers, data) |
| 135 return setmetatable({ func = func, thread = false, state = "ready", notified_state = "ready", | 139 return setmetatable({ func = func or default_func, thread = false, state = "ready", notified_state = "ready", |
| 136 queue = {}, watchers = watchers or empty_watchers, data = data, id = new_id() } | 140 queue = {}, watchers = watchers or { error = default_error_watcher }, data = data, id = new_id() } |
| 137 , runner_mt); | 141 , runner_mt); |
| 138 end | 142 end |
| 139 | 143 |
| 140 -- Add a task item for the runner to process | 144 -- Add a task item for the runner to process |
| 141 function runner_mt:run(input) | 145 function runner_mt:run(input) |