Software /
code /
prosody
Diff
util/promise.lua @ 9514:9db707a86a25
util.promise: Add promise:finally()
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 18 Oct 2018 12:13:17 +0100 |
parent | 9513:4f4f9823bd1d |
child | 9515:2571c65b972f |
line wrap: on
line diff
--- a/util/promise.lua Thu Oct 18 12:12:52 2018 +0100 +++ b/util/promise.lua Thu Oct 18 12:13:17 2018 +0100 @@ -126,6 +126,12 @@ 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;