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

booltrue 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