Exception
DeadmanException
The writer of a StringBuffer exited without ending it: a read throws this once the buffered data is read.
Introduction#
A writer that holds the buffer's deadman switch (getDeadmanSwitch()) and lets go of it without calling end(), as when its coroutine terminates, triggers it: the readers get what it wrote, and then this exception instead of waiting for data that will never come.
Class synopsis#
class DeadmanException extends RuntimeException implements \Throwable, \Stringable, RethrowExceptionInterface {
}Examples#
phasync::run(function () {
$buffer = new phasync\Util\StringBuffer();
phasync::go(function () use ($buffer) {
$switch = $buffer->getDeadmanSwitch();
$buffer->write('partial'); // and exits without $buffer->end()
});
echo $buffer->read(100), "\n"; // partial
try {
$buffer->read(100);
} catch (phasync\DeadmanException $e) {
echo $e->getMessage(), "\n"; // Writer terminated unexpectedly
}
});See also#
StringBuffer::getDeadmanSwitchGet a deadman switch for this object.StringBuffer::readReturns up to$maxLengthbytes, and waits while the buffer is empty and not ended.StringBuffer::endMarks the end of the stream: no more writes are accepted, and readers get the data left and then the end.