Method
Frame::setTimeout
Cancels the frame when $seconds have passed, and makes its run() throw a TimeoutException instead of the cancellation.
Description#
public Frame::setTimeout(
float $seconds
): voidThe deadline counts from the call. Calling it again replaces the deadline. Once it passes, the frame is cancelled with Frame::cancel, which also requests cancellation. The coroutines of the frame see a CancelledException whose previous exception is the TimeoutException, as for Frame::cancel. A run() whose $fn catches the cancellation and returns, returns normally.
Parameters#
- $seconds float
- From now
Errors / Exceptions#
| Exception | When |
|---|---|
LogicException | When the frame's run() has returned |
Examples#
phasync::run(function () {
phasync::frame()->setTimeout(0.5);
phasync::sleep(10);
}); // throws phasync\TimeoutException after 0.5 secondsSee also#
Frame::cancelCancels every coroutine of the frame, and of the frames nested in it, with a CancelledException.phasync::awaitA timeout on one wait