From 3c53df784751cef688a5ff41db26d4d11b7da2f7 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 14 Jun 2020 08:49:32 +0100 Subject: util.async: Call coroutine.close() on dead threads (Lua 5.4) --- util/async.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/util/async.lua b/util/async.lua index 16dce200..24378d8c 100644 --- a/util/async.lua +++ b/util/async.lua @@ -53,7 +53,7 @@ local function runner_continue(thread) return false; end call_watcher(runner, "error", debug.traceback(thread, err)); - runner.state, runner.thread = "ready", nil; + runner.state = "ready"; return runner:run(); elseif state == "ready" then -- If state is 'ready', it is our responsibility to update runner.state from 'waiting'. @@ -159,6 +159,10 @@ function runner_mt:run(input) local q, thread = self.queue, self.thread; if not thread or coroutine.status(thread) == "dead" then + --luacheck: ignore 143/coroutine + if coroutine.close then + coroutine.close(thread); + end self:log("debug", "creating new coroutine"); -- Create a new coroutine for this runner thread = runner_create_thread(self.func, self); -- cgit v1.2.3