Software /
code /
prosody
Comparison
util/async.lua @ 5792:aac4c6147647
util.async: waiter: Remove restriction about wait() being called before done()
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 12 Aug 2013 12:08:51 +0100 |
parent | 5791:2c98061b6b1e |
child | 5793:e8c79796ead9 |
comparison
equal
deleted
inserted
replaced
5791:2c98061b6b1e | 5792:aac4c6147647 |
---|---|
26 local thread = coroutine.running(); | 26 local thread = coroutine.running(); |
27 if not thread then | 27 if not thread then |
28 error("Not running in an async context, see http://prosody.im/doc/developers/async"); | 28 error("Not running in an async context, see http://prosody.im/doc/developers/async"); |
29 end | 29 end |
30 num = num or 1; | 30 num = num or 1; |
31 local waiting; | |
31 return function () | 32 return function () |
33 if num == 0 then return; end -- already done | |
34 waiting = true; | |
32 coroutine.yield("wait"); | 35 coroutine.yield("wait"); |
33 end, function () | 36 end, function () |
34 num = num - 1; | 37 num = num - 1; |
35 if num == 0 then | 38 if num == 0 and waiting then |
36 if not runner_continue(thread) then | 39 runner_continue(thread); |
37 error("done() called without wait()!"); | |
38 end | |
39 end | 40 end |
40 end; | 41 end; |
41 end | 42 end |
42 | 43 |
43 local runner_mt = {}; | 44 local runner_mt = {}; |