Future::isCompleted
(PHP 8.6+, True Async 1.0)
php
public function isCompleted(): boolChecks whether the Future is completed. A Future is considered completed if it contains a result, an error, or has been cancelled.
Return value
bool — true if the Future is completed (successfully, with an error, or cancelled), false otherwise.
Examples
Example #1 Checking Future completion
php
<?php
use Async\Future;
use Async\FutureState;
$state = new FutureState();
$future = new Future($state);
var_dump($future->isCompleted()); // bool(false)
$state->complete(42);
var_dump($future->isCompleted()); // bool(true)Example #2 Checking static factory methods
php
<?php
use Async\Future;
$completed = Future::completed("done");
var_dump($completed->isCompleted()); // bool(true)
$failed = Future::failed(new \RuntimeException("error"));
var_dump($failed->isCompleted()); // bool(true)See also
- Future::isCancelled — Check if the Future is cancelled
- Future::await — Await the Future result