util.promise: Add promise:finally()

This commit is contained in:
Matthew Wild 2018-10-18 12:13:17 +01:00
parent 894fe1b808
commit 681b25e427
2 changed files with 73 additions and 0 deletions

View file

@ -126,6 +126,12 @@ function promise_methods:catch(on_rejected)
return self:next(nil, on_rejected);
end
function promise_methods:finally(on_finally)
local function _on_finally(value) on_finally(); return value; end
local function _on_catch_finally(err) on_finally(); return reject(err); end
return self:next(_on_finally, _on_catch_finally);
end
return {
new = new;
resolve = resolve;