aboutsummaryrefslogtreecommitdiffstats
path: root/util/promise.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2021-03-25 14:32:32 +0000
committerMatthew Wild <mwild1@gmail.com>2021-03-25 14:32:32 +0000
commitfec0d44e89f58dae50063be87a6d9360e012f205 (patch)
tree2bec243fb99a039d6dc2a24638711926c65fe23f /util/promise.lua
parent2141d9d94a7b0c855a99e4444b093f80ee316f75 (diff)
downloadprosody-fec0d44e89f58dae50063be87a6d9360e012f205.tar.gz
prosody-fec0d44e89f58dae50063be87a6d9360e012f205.zip
util.promise: all()/all_settled() pass through non-promise values
Diffstat (limited to 'util/promise.lua')
-rw-r--r--util/promise.lua52
1 files changed, 30 insertions, 22 deletions
diff --git a/util/promise.lua b/util/promise.lua
index 5996176f..89bd1f26 100644
--- a/util/promise.lua
+++ b/util/promise.lua
@@ -95,14 +95,18 @@ local function all(promises)
local settled, results, loop_finished = 0, {}, false;
local total = 0;
for k, v in pairs(promises) do
- total = total + 1;
- v:next(function (value)
- results[k] = value;
- settled = settled + 1;
- if settled == total and loop_finished then
- resolve(results);
- end
- end, reject);
+ if is_promise(v) then
+ total = total + 1;
+ v:next(function (value)
+ results[k] = value;
+ settled = settled + 1;
+ if settled == total and loop_finished then
+ resolve(results);
+ end
+ end, reject);
+ else
+ results[k] = v;
+ end
end
loop_finished = true;
if settled == total then
@@ -116,20 +120,24 @@ local function all_settled(promises)
local settled, results, loop_finished = 0, {}, false;
local total = 0;
for k, v in pairs(promises) do
- total = total + 1;
- v:next(function (value)
- results[k] = { status = "fulfilled", value = value };
- settled = settled + 1;
- if settled == total and loop_finished then
- resolve(results);
- end
- end, function (e)
- results[k] = { status = "rejected", reason = e };
- settled = settled + 1;
- if settled == total and loop_finished then
- resolve(results);
- end
- end);
+ if is_promise(v) then
+ total = total + 1;
+ v:next(function (value)
+ results[k] = { status = "fulfilled", value = value };
+ settled = settled + 1;
+ if settled == total and loop_finished then
+ resolve(results);
+ end
+ end, function (e)
+ results[k] = { status = "rejected", reason = e };
+ settled = settled + 1;
+ if settled == total and loop_finished then
+ resolve(results);
+ end
+ end);
+ else
+ results[k] = v;
+ end
end
loop_finished = true;
if settled == total then