From 69d44aaf393011d15bb81f801d9c59920c6d6bca Mon Sep 17 00:00:00 2001 From: s1n7ax Date: Tue, 5 Dec 2023 14:46:53 +0530 Subject: [PATCH] feat: add await_handle_ok handler --- lua/java-core/utils/async.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lua/java-core/utils/async.lua b/lua/java-core/utils/async.lua index 8649de7..3381b14 100644 --- a/lua/java-core/utils/async.lua +++ b/lua/java-core/utils/async.lua @@ -116,6 +116,16 @@ local await_handle_error = function(defer) return value end +local await_handle_ok = function(defer) + local ok, value = co.yield(defer) + + if not ok then + error(value) + end + + return value +end + local await_all = function(defer) assert(type(defer) == 'table', 'type error :: expected table') return co.yield(join(defer)) @@ -124,6 +134,7 @@ end return { sync = async, wait_handle_error = await_handle_error, + wait_handle_ok = await_handle_ok, wait = await, wait_all = await_all, wrap = wrap,