Comparison

util/promise.lua @ 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
parent 9510:8ef46d09386a
child 9513:4f4f9823bd1d
comparison
equal deleted inserted replaced
9511:cb88d729e98d 9512:439cf3bbe5f3
44 44
45 end 45 end
46 local function _reject(e) 46 local function _reject(e)
47 if resolved then return; end 47 if resolved then return; end
48 resolved = true; 48 resolved = true;
49 if promise_settle(p, "rejected", next_rejected, p._pending_on_rejected, e) then 49 if is_promise(e) then
50 e:next(new_resolve_functions(p));
51 elseif promise_settle(p, "rejected", next_rejected, p._pending_on_rejected, e) then
50 p.reason = e; 52 p.reason = e;
51 end 53 end
52 end 54 end
53 return _resolve, _reject; 55 return _resolve, _reject;
54 end 56 end