Coroutine::isRunning
(PHP 8.6+, True Async 1.0)
php
public Coroutine::isRunning(): boolChecks whether the coroutine is currently executing. A coroutine is considered running if it has been started and has not yet completed.
Return Value
bool -- true if the coroutine is running and not completed.
Examples
Example #1 Checking execution state
php
<?php
use function Async\spawn;
use function Async\await;
$coroutine = spawn(function() {
// Inside the coroutine isRunning() == true
var_dump(\Async\current_coroutine()->isRunning()); // bool(true)
return "done";
});
// Outside -- coroutine is suspended or not yet started
var_dump($coroutine->isRunning()); // bool(false)See Also
- Coroutine::isStarted -- Check if started
- Coroutine::isSuspended -- Check suspension
- Coroutine::isCompleted -- Check completion