Software /
code /
prosody
Comparison
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 |
comparison
equal
deleted
inserted
replaced
9513:4f4f9823bd1d | 9514:9db707a86a25 |
---|---|
124 | 124 |
125 function promise_methods:catch(on_rejected) | 125 function promise_methods:catch(on_rejected) |
126 return self:next(nil, on_rejected); | 126 return self:next(nil, on_rejected); |
127 end | 127 end |
128 | 128 |
129 function promise_methods:finally(on_finally) | |
130 local function _on_finally(value) on_finally(); return value; end | |
131 local function _on_catch_finally(err) on_finally(); return reject(err); end | |
132 return self:next(_on_finally, _on_catch_finally); | |
133 end | |
134 | |
129 return { | 135 return { |
130 new = new; | 136 new = new; |
131 resolve = resolve; | 137 resolve = resolve; |
132 reject = reject; | 138 reject = reject; |
133 all = all; | 139 all = all; |