diff options
author | Matthew Wild <mwild1@gmail.com> | 2018-10-18 12:11:50 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2018-10-18 12:11:50 +0100 |
commit | ba60cb91ec9494b595df78892cfb3b1e90fe3865 (patch) | |
tree | 04f24e8f527e1eaa6090455ea8f7bb43ab9de5d4 | |
parent | bd42adb56b30f4593fdec4c86e3ca18750b5e37d (diff) | |
download | prosody-ba60cb91ec9494b595df78892cfb3b1e90fe3865.tar.gz prosody-ba60cb91ec9494b595df78892cfb3b1e90fe3865.zip |
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.
-rw-r--r-- | util/promise.lua | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/util/promise.lua b/util/promise.lua index 1f48eb9f..2583baa2 100644 --- a/util/promise.lua +++ b/util/promise.lua @@ -46,7 +46,9 @@ local function new_resolve_functions(p) 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 |