diff options
author | Matthew Wild <mwild1@gmail.com> | 2018-10-18 18:03:31 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2018-10-18 18:03:31 +0100 |
commit | 20e9a8f983329182742a654934aceec17fb204be (patch) | |
tree | 9956f487437a70fcdfcfeefb3475e6a55932f939 /util/promise.lua | |
parent | be388c504e6451b56c6a1c04dc7e2322f8e05ec5 (diff) | |
download | prosody-20e9a8f983329182742a654934aceec17fb204be.tar.gz prosody-20e9a8f983329182742a654934aceec17fb204be.zip |
util.promise: Add promise.try()
Diffstat (limited to 'util/promise.lua')
-rw-r--r-- | util/promise.lua | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/util/promise.lua b/util/promise.lua index b5660488..b1c6be02 100644 --- a/util/promise.lua +++ b/util/promise.lua @@ -51,6 +51,7 @@ local function new_resolve_functions(p) if resolved then return; end resolved = true; if is_promise(e) then + print ("WOAH") assert(false) e:next(new_resolve_functions(p)); elseif promise_settle(p, "rejected", next_rejected, p._pending_on_rejected, e) then p.reason = e; @@ -117,6 +118,10 @@ local function reject(v) end); end +local function try(f) + return resolve():next(function () return f(); end); +end + function promise_methods:next(on_fulfilled, on_rejected) return new(function (resolve, reject) --luacheck: ignore 431/resolve 431/reject self:_next( @@ -142,4 +147,5 @@ return { reject = reject; all = all; race = race; + try = try; } |