Exception
ChannelException
A channel operation failed: it was written to after it was closed, or the wait looked like a deadlock.
Introduction#
write() throws it on a closed channel. The creator-coroutine check throws it from the coroutine that called phasync::channel(), when it waits on the channel and no other coroutine has done so within about 100 ms; see phasync::channel, and activate() to switch the check off. A timeout is a TimeoutException, not this.
Class synopsis#
class ChannelException extends RuntimeException implements \Throwable, \Stringable, RethrowExceptionInterface {
}Examples#
phasync::run(function () {
phasync::channel($read, $write, 1);
phasync::go(fn () => $read->close());
phasync::sleep(0.01);
try {
$write->write('late');
} catch (phasync\ChannelException $e) {
echo $e->getMessage(), "\n"; // Channel is closed
}
});See also#
phasync::channelCreates a channel and returns its two ends in$readand$write.WriteChannelInterface::writeSends a value, and waits while the channel cannot take it: for a reader on an unbuffered channel, for room on a full buffer.