diff options
| author | William Boman <william@redwill.se> | 2022-08-15 21:03:06 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-15 21:03:06 +0200 |
| commit | 3c62386a396ae0c1cd7adbaacc379eb4af072a65 (patch) | |
| tree | 4d00d20958839a04e6a996c11b97724c762e491a /lua/mason-core/async/init.lua | |
| parent | chore: update generated code (#295) (diff) | |
| download | mason-3c62386a396ae0c1cd7adbaacc379eb4af072a65.tar mason-3c62386a396ae0c1cd7adbaacc379eb4af072a65.tar.gz mason-3c62386a396ae0c1cd7adbaacc379eb4af072a65.tar.bz2 mason-3c62386a396ae0c1cd7adbaacc379eb4af072a65.tar.lz mason-3c62386a396ae0c1cd7adbaacc379eb4af072a65.tar.xz mason-3c62386a396ae0c1cd7adbaacc379eb4af072a65.tar.zst mason-3c62386a396ae0c1cd7adbaacc379eb4af072a65.zip | |
refactor: introduce selene, harden type defs, and use proper EmmyLua syntax (#296)
Diffstat (limited to 'lua/mason-core/async/init.lua')
| -rw-r--r-- | lua/mason-core/async/init.lua | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/lua/mason-core/async/init.lua b/lua/mason-core/async/init.lua index 7805cade..05401ca2 100644 --- a/lua/mason-core/async/init.lua +++ b/lua/mason-core/async/init.lua @@ -39,7 +39,7 @@ local function table_pack(...) end ---@param async_fn fun(...) ----@param should_reject_err boolean|nil: Whether the provided async_fn takes a callback with the signature `fun(err, result)` +---@param should_reject_err boolean? Whether the provided async_fn takes a callback with the signature `fun(err, result)` local function promisify(async_fn, should_reject_err) return function(...) local args = table_pack(...) @@ -64,11 +64,12 @@ local function promisify(async_fn, should_reject_err) end local function new_execution_context(suspend_fn, callback, ...) + ---@type thread? local thread = co.create(suspend_fn) local cancelled = false local step step = function(...) - if cancelled then + if cancelled or not thread then return end local ok, promise_or_result = co.resume(thread, ...) @@ -103,7 +104,6 @@ end ---@generic T ---@param suspend_fn T ----@return T exports.scope = function(suspend_fn) return function(...) return new_execution_context(suspend_fn, function(success, err) |
