Software /
code /
prosody
Diff
util/promise.lua @ 11485:7d42ed3a8a40
util.promise: all()/all_settled() pass through non-promise values
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 25 Mar 2021 14:32:32 +0000 |
parent | 11484:a0120e935442 |
child | 11486:78d843faaffc |
line wrap: on
line diff
--- a/util/promise.lua Thu Mar 25 14:28:38 2021 +0000 +++ b/util/promise.lua Thu Mar 25 14:32:32 2021 +0000 @@ -95,14 +95,18 @@ 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 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