aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2018-03-17 14:54:48 +0000
committerMatthew Wild <mwild1@gmail.com>2018-03-17 14:54:48 +0000
commit9d1d5d021bd72d872b8b4c5abd3cf3548933f930 (patch)
treebaddae87b7a48b7cdbc752e40f1e99d924bb7fad
parent3802dc1555643ca6ab57593c47457346ab11ca98 (diff)
downloadprosody-9d1d5d021bd72d872b8b4c5abd3cf3548933f930.tar.gz
prosody-9d1d5d021bd72d872b8b4c5abd3cf3548933f930.zip
util.async: Behaviour change: continue to process queued items after errors
-rw-r--r--spec/util_async_spec.lua24
-rw-r--r--util/async.lua3
2 files changed, 27 insertions, 0 deletions
diff --git a/spec/util_async_spec.lua b/spec/util_async_spec.lua
index e4e74e80..24f4d8c8 100644
--- a/spec/util_async_spec.lua
+++ b/spec/util_async_spec.lua
@@ -156,6 +156,30 @@ describe("util.async", function()
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 --git a/util/async.lua b/util/async.lua
index 0dde1f32..8756c81a 100644
--- a/util/async.lua
+++ b/util/async.lua
@@ -180,6 +180,9 @@ function runner_mt:run(input)
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