util/async.lua
changeset 8612 9f6ab206d741
parent 8607 1c8c7fd259c8
child 8613 b03c7884fade
--- a/util/async.lua	Fri Mar 16 22:19:33 2018 +0000
+++ b/util/async.lua	Fri Mar 16 22:26:15 2018 +0000
@@ -17,13 +17,18 @@
 	end
 	local ok, state, runner = coroutine.resume(thread);
 	if not ok then
+		local err = state;
 		-- Running the coroutine failed, which means we have to find the runner manually,
 		-- in order to inform the error handler
 		local level = 0;
 		while debug.getinfo(thread, level, "") do level = level + 1; end
 		ok, runner = debug.getlocal(thread, level-1, 1);
 		local error_handler = runner.watchers.error;
-		if error_handler then error_handler(runner, debug.traceback(thread, state)); end
+		if error_handler then error_handler(runner, debug.traceback(thread, err)); end
+		local ready_handler = runner.watchers.ready;
+		runner.state, runner.thread = "ready", nil;
+		if ready_handler then ready_handler(runner); end
+		runner.notified_state = "ready";
 	elseif state == "ready" then
 		-- If state is 'ready', it is our responsibility to update runner.state from 'waiting'.
 		-- We also have to :run(), because the queue might have further items that will not be