From 3c62386a396ae0c1cd7adbaacc379eb4af072a65 Mon Sep 17 00:00:00 2001 From: William Boman Date: Mon, 15 Aug 2022 21:03:06 +0200 Subject: refactor: introduce selene, harden type defs, and use proper EmmyLua syntax (#296) --- lua/mason-core/async/init.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lua/mason-core/async/init.lua') 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) -- cgit v1.2.3-70-g09d2