Coroutine::isRunning

(PHP 8.6+, True Async 1.0)

public Coroutine::isRunning(): bool

Checks whether the coroutine is currently executing. A coroutine is considered running if it has been started and has not yet completed.

Return Value

booltrue if the coroutine is running and not completed.

Examples

Example #1 Checking execution state

<?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