aboutsummaryrefslogtreecommitdiffstats
path: root/util/promise.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2018-10-18 12:13:17 +0100
committerMatthew Wild <mwild1@gmail.com>2018-10-18 12:13:17 +0100
commitcdd7a0fbf86fad5d905e1fec47fd315ba800f7ea (patch)
tree5eef7eee17878919d4aeb406551748dd7f6e4c54 /util/promise.lua
parenta66d4a2f82a23c0c7600e04b09d862c2f1a973a0 (diff)
downloadprosody-cdd7a0fbf86fad5d905e1fec47fd315ba800f7ea.tar.gz
prosody-cdd7a0fbf86fad5d905e1fec47fd315ba800f7ea.zip
util.promise: Add promise:finally()
Diffstat (limited to 'util/promise.lua')
-rw-r--r--util/promise.lua6
1 files changed, 6 insertions, 0 deletions
diff --git a/util/promise.lua b/util/promise.lua
index c988ddc9..8b57c822 100644
--- a/util/promise.lua
+++ b/util/promise.lua
@@ -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;