Coroutine::isSuspended
(PHP 8.6+, True Async 1.0)
public Coroutine::isSuspended(): bool
Checks whether the coroutine is suspended. A coroutine becomes suspended when suspend() is called, during I/O operations, or while waiting with await().
Return Value
bool – true if the coroutine is suspended.
Examples
Example #1 Checking suspension
<?php
use function Async\spawn;
use function Async\suspend;
$coroutine = spawn(function() {
suspend();
return "done";
});
suspend(); // let the coroutine start and suspend
var_dump($coroutine->isSuspended()); // bool(true)
var_dump($coroutine->isStarted()); // bool(true)
var_dump($coroutine->isCompleted()); // bool(false)
See Also
- Coroutine::isRunning – Check execution
- Coroutine::getTrace – Call stack of a suspended coroutine
- suspend() – Suspend the current coroutine