Software /
code /
prosody
Comparison
plugins/mod_admin_shell.lua @ 13591:382d1a92006f
mod_admin_shell: Don't pause async thread while waiting for promise result
This allows us to continue sending/receiving on the session, for example if
the promise will be resolved by other data that the client is going to send.
Specifically, this allows the repl-request-input to work without a deadlock.
It does open the door to interleaved commands/results, which may not be a good
thing overall, but can be restricted separately if necessary (e.g. a flag on
the session).
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 07 Jan 2025 18:15:50 +0000 |
parent | 13582:67c9fc643873 |
child | 13593:f57872788424 |
comparison
equal
deleted
inserted
replaced
13590:d66f30855822 | 13591:382d1a92006f |
---|---|
264 event.origin.send(result); | 264 event.origin.send(result); |
265 return; | 265 return; |
266 end | 266 end |
267 end | 267 end |
268 | 268 |
269 local function send_result(taskok, message) | |
270 if not message then | |
271 if type(taskok) ~= "string" and useglobalenv then | |
272 taskok = session.serialize(taskok); | |
273 end | |
274 result:text("Result: "..tostring(taskok)); | |
275 elseif (not taskok) and message then | |
276 result.attr.type = "error"; | |
277 result:text("Error: "..tostring(message)); | |
278 else | |
279 result:text("OK: "..tostring(message)); | |
280 end | |
281 | |
282 event.origin.send(result); | |
283 end | |
284 | |
269 local taskok, message = chunk(); | 285 local taskok, message = chunk(); |
270 | 286 |
271 if promise.is_promise(taskok) then | 287 if promise.is_promise(taskok) then |
272 taskok, message = async.wait_for(taskok); | 288 taskok:next(function (resolved_message) |
273 end | 289 send_result(true, resolved_message); |
274 | 290 end, function (rejected_message) |
275 if not message then | 291 send_result(nil, rejected_message); |
276 if type(taskok) ~= "string" and useglobalenv then | 292 end); |
277 taskok = session.serialize(taskok); | |
278 end | |
279 result:text("Result: "..tostring(taskok)); | |
280 elseif (not taskok) and message then | |
281 result.attr.type = "error"; | |
282 result:text("Error: "..tostring(message)); | |
283 else | 293 else |
284 result:text("OK: "..tostring(message)); | 294 send_result(taskok, message); |
285 end | 295 end |
286 | |
287 event.origin.send(result); | |
288 end | 296 end |
289 | 297 |
290 module:hook("admin/repl-input", function (event) | 298 module:hook("admin/repl-input", function (event) |
291 local ok, err = pcall(handle_line, event); | 299 local ok, err = pcall(handle_line, event); |
292 if not ok then | 300 if not ok then |