Coroutine::isRunning

(PHP 8.6+, True Async 1.0)

public Coroutine::isRunning(): bool

Prueft, ob die Coroutine gerade ausgefuehrt wird. Eine Coroutine gilt als laufend, wenn sie gestartet wurde und noch nicht abgeschlossen ist.

Rueckgabewert

booltrue, wenn die Coroutine laeuft und nicht abgeschlossen ist.

Beispiele

Beispiel #1 Ausfuehrungsstatus pruefen

<?php

use function Async\spawn;
use function Async\await;

$coroutine = spawn(function() {
    // Innerhalb der Coroutine ist isRunning() == true
    var_dump(\Async\current_coroutine()->isRunning()); // bool(true)
    return "done";
});

// Ausserhalb -- Coroutine ist unterbrochen oder noch nicht gestartet
var_dump($coroutine->isRunning()); // bool(false)

Siehe auch