util.async: ensure change in e77b37de482e applies after out-of-loop resume also
authorMatthew Wild <mwild1@gmail.com>
Sat, 17 Mar 2018 17:28:07 +0000
changeset 8619 a15c891c6232
parent 8618 e77b37de482e
child 8620 fafb4036771c
util.async: ensure change in e77b37de482e applies after out-of-loop resume also
spec/util_async_spec.lua
util/async.lua
--- a/spec/util_async_spec.lua	Sat Mar 17 14:54:48 2018 +0000
+++ b/spec/util_async_spec.lua	Sat Mar 17 17:28:07 2018 +0000
@@ -180,6 +180,31 @@
 				assert.spy(runner.watchers.error).was.called(1);
 				assert.equal(last_item, "two");
 			end);
+
+			it("should continue to process work items during resume", function ()
+				local wait, done, last_item;
+				local runner_func = spy.new(function (item)
+					if item == "error" then
+						error("test error");
+					elseif item == "wait-error" then
+						wait, done = async.waiter();
+						wait();
+						error("test error");
+					end
+					last_item = item;
+				end);
+				local runner = async.runner(runner_func, { error = spy.new(function () end) });
+				runner:enqueue("one");
+				runner:enqueue("wait-error");
+				runner:enqueue("two");
+				runner:run();
+				done();
+				assert.equal(r.state, "ready");
+				assert.equal(r.state, r.notified_state);
+				assert.spy(runner_func).was.called(3);
+				assert.spy(runner.watchers.error).was.called(1);
+				assert.equal(last_item, "two");
+			end);
 		end);
 	end);
 	describe("#waiter", function()
--- a/util/async.lua	Sat Mar 17 14:54:48 2018 +0000
+++ b/util/async.lua	Sat Mar 17 17:28:07 2018 +0000
@@ -32,8 +32,7 @@
 		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";
+		return runner:run();
 	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