TaskSet::isFinished
(PHP 8.6+, True Async 1.0)
php
public TaskSet::isFinished(): boolReturns true if there are no active coroutines and the task queue is empty.
If the set is not closed, this state may be temporary — new tasks can be added via spawn().
Return Value
true if all tasks are finished. false otherwise.
Examples
Example #1 Checking state
php
<?php
use Async\TaskSet;
spawn(function() {
$set = new TaskSet();
echo $set->isFinished() ? "yes\n" : "no\n"; // "yes"
$set->spawn(fn() => "task");
echo $set->isFinished() ? "yes\n" : "no\n"; // "no"
$set->close();
$set->joinAll()->await();
echo $set->isFinished() ? "yes\n" : "no\n"; // "yes"
});See Also
- TaskSet::isClosed — Check if the set is closed
- TaskSet::count — Number of tasks