Mercurial > prosody-hg
comparison util/async.lua @ 13332:17cb965e55b7
util.async: Record current work item in the runner object
Mostly expected to be useful for debugging purposes.
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Tue, 21 Nov 2023 18:13:42 +0000 |
| parents | 5206314d6c70 |
| children | fa4143163e01 |
comparison
equal
deleted
inserted
replaced
| 13331:5206314d6c70 | 13332:17cb965e55b7 |
|---|---|
| 199 local consumed; | 199 local consumed; |
| 200 -- Loop through queue items, and attempt to run them | 200 -- Loop through queue items, and attempt to run them |
| 201 for i = 1,n do | 201 for i = 1,n do |
| 202 local queued_input = q[i]; | 202 local queued_input = q[i]; |
| 203 self:log("Resuming thread with new item [%s]", thread); | 203 self:log("Resuming thread with new item [%s]", thread); |
| 204 self.current_item = queued_input; | |
| 204 local ok, new_state = coroutine.resume(thread, queued_input); | 205 local ok, new_state = coroutine.resume(thread, queued_input); |
| 205 if not ok then | 206 if not ok then |
| 206 -- There was an error running the coroutine, save the error, mark runner as ready to begin again | 207 -- There was an error running the coroutine, save the error, mark runner as ready to begin again |
| 207 consumed, state, err = i, "ready", debug.traceback(thread, new_state); | 208 consumed, state, err = i, "ready", debug.traceback(thread, new_state); |
| 208 self.thread = nil; | 209 self.thread = nil; |
| 225 end | 226 end |
| 226 n = #q; | 227 n = #q; |
| 227 end | 228 end |
| 228 -- Runner processed all items it can, so save current runner state | 229 -- Runner processed all items it can, so save current runner state |
| 229 self.state = state; | 230 self.state = state; |
| 231 if state == "ready" and self.current_item then | |
| 232 self.current_item = nil; | |
| 233 end | |
| 234 | |
| 230 if err or state ~= self.notified_state then | 235 if err or state ~= self.notified_state then |
| 231 self:log("debug", "changed state from %s to %s [%s %s]", self.notified_state, err and ("error ("..state..")") or state, self.thread, self.thread and coroutine.status(self.thread)); | 236 self:log("debug", "changed state from %s to %s [%s %s]", self.notified_state, err and ("error ("..state..")") or state, self.thread, self.thread and coroutine.status(self.thread)); |
| 232 if err then | 237 if err then |
| 233 state = "error" | 238 state = "error" |
| 234 else | 239 else |
