Comparison

util/async.lua @ 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
parent 10928:79faf5b98395
child 10931:558f0555ba02
comparison
equal deleted inserted replaced
10929:ad5e373b1419 10930:69a4b0e3565f
51 if not runner then 51 if not runner then
52 log("error", "unexpected async state: unable to locate runner during error handling"); 52 log("error", "unexpected async state: unable to locate runner during error handling");
53 return false; 53 return false;
54 end 54 end
55 call_watcher(runner, "error", debug.traceback(thread, err)); 55 call_watcher(runner, "error", debug.traceback(thread, err));
56 runner.state, runner.thread = "ready", nil; 56 runner.state = "ready";
57 return runner:run(); 57 return runner:run();
58 elseif state == "ready" then 58 elseif state == "ready" then
59 -- If state is 'ready', it is our responsibility to update runner.state from 'waiting'. 59 -- If state is 'ready', it is our responsibility to update runner.state from 'waiting'.
60 -- We also have to :run(), because the queue might have further items that will not be 60 -- We also have to :run(), because the queue might have further items that will not be
61 -- processed otherwise. FIXME: It's probably best to do this in a nexttick (0 timer). 61 -- processed otherwise. FIXME: It's probably best to do this in a nexttick (0 timer).
157 return true, self.state, #self.queue; 157 return true, self.state, #self.queue;
158 end 158 end
159 159
160 local q, thread = self.queue, self.thread; 160 local q, thread = self.queue, self.thread;
161 if not thread or coroutine.status(thread) == "dead" then 161 if not thread or coroutine.status(thread) == "dead" then
162 --luacheck: ignore 143/coroutine
163 if coroutine.close then
164 coroutine.close(thread);
165 end
162 self:log("debug", "creating new coroutine"); 166 self:log("debug", "creating new coroutine");
163 -- Create a new coroutine for this runner 167 -- Create a new coroutine for this runner
164 thread = runner_create_thread(self.func, self); 168 thread = runner_create_thread(self.func, self);
165 self.thread = thread; 169 self.thread = thread;
166 end 170 end