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.
--- 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