cond() ->
cond
Create a condition, on which tasks wait for one another
Returns a condition: a list of waiting tasks that another task, a signal
handler or a cleanup wakes. A wait with no timeout holds no timer and no
fd. A condition made outside lev.run() serves every loop after it.
cond:wait(timeout_or_opts) parks the calling task. It returns true
once a signal takes it, nil, "timeout", or nil, "cancelled". The
argument is a timeout in seconds or { timeout = N, cancel = token }.
A timeout at or below zero returns nil, "timeout" with no wait, and a
token that has fired returns nil, "cancelled" with none.cond:signal() wakes the task that has waited longest. Returns true
if one waited, false otherwise.cond:broadcast() wakes every waiting task. Returns their count.A condition has no memory: a signal with no waiter is dropped. Check the state the wait is for, then wait, with no other wait between the two, and check again after the wake:
while #queue == 0 do
if not ready:wait() then
return
end
end
signal and broadcast only queue the waiters, which run on the loop's
next turn. Neither waits, so a signal handler and a cleanup may call them.
wait raises lev: wait outside a task there.