# HG changeset patch # User Matthew Wild # Date 1521298488 0 # Node ID e77b37de482ee11bd647a4d5ad1d20afb2f673a6 # Parent bfbafeced0c47edf75a6508f298aa039a914d504 util.async: Behaviour change: continue to process queued items after errors diff -r bfbafeced0c4 -r e77b37de482e spec/util_async_spec.lua --- a/spec/util_async_spec.lua Sat Mar 17 11:47:07 2018 +0000 +++ b/spec/util_async_spec.lua Sat Mar 17 14:54:48 2018 +0000 @@ -156,6 +156,30 @@ assert.equal(r.state, "ready"); assert.equal(last_processed_item, "hello again"); end); + + it("should continue to process work items", 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("error"); + runner:enqueue("two"); + runner:run(); + 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() diff -r bfbafeced0c4 -r e77b37de482e util/async.lua --- a/util/async.lua Sat Mar 17 11:47:07 2018 +0000 +++ b/util/async.lua Sat Mar 17 14:54:48 2018 +0000 @@ -180,6 +180,9 @@ local handler = self.watchers[state]; if handler then handler(self, err); end end + if n > 0 then + return self:run(); + end return true, state, n; end