aboutsummaryrefslogtreecommitdiffstats
path: root/util/async.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2013-08-12 12:08:51 +0100
committerMatthew Wild <mwild1@gmail.com>2013-08-12 12:08:51 +0100
commit516179867e7ffbe56343375aa0d8abcf41dee83a (patch)
tree16be476f3044414bc2d4f0f21eb49c37eb91cba7 /util/async.lua
parentd135b8fef982f97c0912444d0dc79688a2670322 (diff)
downloadprosody-516179867e7ffbe56343375aa0d8abcf41dee83a.tar.gz
prosody-516179867e7ffbe56343375aa0d8abcf41dee83a.zip
util.async: waiter: Remove restriction about wait() being called before done()
Diffstat (limited to 'util/async.lua')
-rw-r--r--util/async.lua9
1 files changed, 5 insertions, 4 deletions
diff --git a/util/async.lua b/util/async.lua
index afbaba5c..c81f8639 100644
--- a/util/async.lua
+++ b/util/async.lua
@@ -28,14 +28,15 @@ local function waiter(num)
error("Not running in an async context, see http://prosody.im/doc/developers/async");
end
num = num or 1;
+ local waiting;
return function ()
+ if num == 0 then return; end -- already done
+ waiting = true;
coroutine.yield("wait");
end, function ()
num = num - 1;
- if num == 0 then
- if not runner_continue(thread) then
- error("done() called without wait()!");
- end
+ if num == 0 and waiting then
+ runner_continue(thread);
end
end;
end