Software /
code /
prosody
Changeset
9512:439cf3bbe5f3
util.promise: Also support automatic resolution by returning a promise from an on_reject handler
Originally unimplemented because it wasn't clear to me what the correct behaviour was, but the A+
spec is clear that both onFulfilled and onRejected may return a promise.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 18 Oct 2018 12:11:50 +0100 |
parents | 9511:cb88d729e98d |
children | 9513:4f4f9823bd1d |
files | util/promise.lua |
diffstat | 1 files changed, 3 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/util/promise.lua Thu Oct 18 12:04:14 2018 +0100 +++ b/util/promise.lua Thu Oct 18 12:11:50 2018 +0100 @@ -46,7 +46,9 @@ local function _reject(e) if resolved then return; end resolved = true; - if promise_settle(p, "rejected", next_rejected, p._pending_on_rejected, e) then + if is_promise(e) then + e:next(new_resolve_functions(p)); + elseif promise_settle(p, "rejected", next_rejected, p._pending_on_rejected, e) then p.reason = e; end end