phasync
Frame / setTimeout

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
): void

The 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#

ExceptionWhen
LogicExceptionWhen the frame's run() has returned

Examples#

Example 1
phasync::run(function () {
    phasync::frame()->setTimeout(0.5);
    phasync::sleep(10);
});   // throws phasync\TimeoutException after 0.5 seconds

See also#

  • Frame::cancelCancels every coroutine of the frame, and of the frames nested in it, with a CancelledException.
  • phasync::awaitA timeout on one wait