Manual
Waiting and timeouts
Sleep, wait for a stream or a flag, and what happens when the wait runs out.
Introduction#
phasync::sleep waits without blocking the process; phasync::readable and phasync::writable wait for a stream to be ready for the next read or write. Every wait in phasync takes an optional timeout and throws the same TimeoutException when it runs out, whether it is a sleep, a stream, a channel, or phasync::await itself.
Examples#
- All examples of this topic – 9 with their output.
Reference#
phasync::sleep– Pauses the current coroutine for $seconds, and lets the others run meanwhile.phasync::idle– Suspends the current coroutine until the event loop has had nothing to run for at least $after seconds: the ready queue and the callback queue are both empty, and an immediate poll finds no I/O ready.phasync::readable– Suspends the coroutine until the stream can be read without blocking, and returns the stream.phasync::writable– Suspends the coroutine until the stream can be written without blocking, and returns the stream.phasync::raiseFlag– Wakes every coroutine waiting for $signal in phasync::awaitFlag, and returns how many it woke.phasync::awaitFlag– Suspends the current coroutine until $signal is raised with phasync::raiseFlag.IOException– A stream wait failed: the value was no stream, the stream was closed while waited for, or polling failed.SelectableInterface– An object that can be asked whether using it would block, and waited for until it would not.TimeoutException– A wait with a timeout ran out before it was satisfied.