From 86a6492eb08c6990824d23d90a5675c8b3c76695 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 12 Aug 2013 12:08:51 +0100 Subject: util.async: waiter: Remove restriction about wait() being called before done() --- util/async.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'util/async.lua') 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 -- cgit v1.2.3