lev.cond

lev

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.

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.