TaskSet::isFinished
(PHP 8.6+, True Async 1.0)
public TaskSet::isFinished(): bool
Returns true if there are no active coroutines and the task queue is empty.
If the set is not sealed, 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
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->seal();
$set->joinAll()->await();
echo $set->isFinished() ? "yes\n" : "no\n"; // "yes"
});
See Also
- TaskSet::isSealed — Check if the set is sealed
- TaskSet::count — Number of tasks