Changeset

10930:69a4b0e3565f

util.async: Call coroutine.close() on dead threads (Lua 5.4)
author Matthew Wild <mwild1@gmail.com>
date Sun, 14 Jun 2020 08:49:32 +0100
parents 10929:ad5e373b1419
children 10931:558f0555ba02
files util/async.lua
diffstat 1 files changed, 5 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/util/async.lua	Sat Jun 13 14:40:41 2020 +0200
+++ b/util/async.lua	Sun Jun 14 08:49:32 2020 +0100
@@ -53,7 +53,7 @@
 			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 @@
 
 	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);