From 681b25e42710b31a5cca6cf9c5b52cc811b6dcea Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 18 Oct 2018 12:13:17 +0100 Subject: util.promise: Add promise:finally() --- util/promise.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'util') 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; -- cgit v1.2.3