Menu
Reference
- Manticore\Ds
- Async
- Classes
- AggregateError
- CancellationToken
- CancelledException
- Channel
- ChannelClosedException
- Context
- DeadlockException
- Mutex
- Once
- Pool
- Received
- SelectCase
- Selected
- Semaphore
- Settled
- Task
- TaskGroup
- TimeoutException
- Functions
- async()
- awaitAll()
- awaitAllSettled()
- awaitAny()
- channel()
- delay()
- dump()
- dumpOn()
- failure()
- group()
- mapConcurrent()
- mapSettled()
- readFile()
- select()
- selectNow()
- selectWithin()
- shield()
- shutdownOn()
- spawn()
- stats()
- timeout()
- watchdog()
- writeFile()
- Http
- Http\WebSocket
- Buffer
- Process
- Io\Poll
- Manticore\Sapi
- Ffi
TimeoutException
finalclass
final class TimeoutException extends \RuntimeException
Thrown when a deadline elapses before the work finishes.
Raised by timeout(), Task::awaitWithin() and Pool::acquire() with a timeout. By the time it is thrown, the work that was under the deadline has been cancelled and joined.
Example
use Async\CancelledException;
use Async\TimeoutException;
use function Async\async;
use function Async\delay;
use function Async\spawn;
use function Async\timeout;
async(function () {
// The body finishes in time: timeout() just returns its value.
echo timeout(1.0, fn() => "in time") . "\n";
// The deadline expires: the body AND everything it spawned are cancelled
// and joined before TimeoutException is thrown.
try {
timeout(0.05, function () {
spawn(function () {
try {
delay(10.0);
} catch (CancelledException $e) {
echo "child cancelled\n";
throw $e;
}
});
delay(10.0);
});
} catch (TimeoutException $e) {
echo "timed out\n";
}
});Output
in time
child cancelled
timed outSee also: timeout, Task::awaitWithin, Pool::acquire