phasync
Streams and files / DeadmanException

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#

Example 1
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#