Software / code / prosody
Comparison
plugins/mod_admin_shell.lua @ 11949:ae4bc56f18e0
mod_admin_shell: Wait for promises
I've typed `>require"util.async".wait_for(...)` for the last time!
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 26 Nov 2021 22:26:48 +0100 |
| parent | 11946:c0a01e5f5656 |
| child | 11950:d2a9e95fd27b |
comparison
equal
deleted
inserted
replaced
| 11948:dca75cc6fc5a | 11949:ae4bc56f18e0 |
|---|---|
| 33 local has_pposix, pposix = pcall(require, "util.pposix"); | 33 local has_pposix, pposix = pcall(require, "util.pposix"); |
| 34 local async = require "util.async"; | 34 local async = require "util.async"; |
| 35 local serialization = require "util.serialization"; | 35 local serialization = require "util.serialization"; |
| 36 local serialize_config = serialization.new ({ fatal = false, unquoted = true}); | 36 local serialize_config = serialization.new ({ fatal = false, unquoted = true}); |
| 37 local time = require "util.time"; | 37 local time = require "util.time"; |
| 38 local promise = require "util.promise"; | |
| 38 | 39 |
| 39 local t_insert = table.insert; | 40 local t_insert = table.insert; |
| 40 local t_concat = table.concat; | 41 local t_concat = table.concat; |
| 41 | 42 |
| 42 local format_number = require "util.human.units".format; | 43 local format_number = require "util.human.units".format; |
| 170 return; | 171 return; |
| 171 end | 172 end |
| 172 end | 173 end |
| 173 | 174 |
| 174 local taskok, message = chunk(); | 175 local taskok, message = chunk(); |
| 176 | |
| 177 if promise.is_promise(taskok) then | |
| 178 taskok, message = async.wait_for(taskok); | |
| 179 end | |
| 175 | 180 |
| 176 if not message then | 181 if not message then |
| 177 if type(taskok) ~= "string" and useglobalenv then | 182 if type(taskok) ~= "string" and useglobalenv then |
| 178 taskok = session.serialize(taskok); | 183 taskok = session.serialize(taskok); |
| 179 end | 184 end |