TaskSet::awaitCompletion
(PHP 8.6+, True Async 1.0)
public TaskSet::awaitCompletion(): void
Suspends the current coroutine until all tasks in the set are completed.
The set must be sealed before calling this method.
Unlike joinAll(), this method does not throw exceptions on task errors
and does not return results.
Errors
Throws Async\AsyncException if the set is not sealed.
Examples
Example #1 Waiting for completion
<?php
use Async\TaskSet;
spawn(function() {
$set = new TaskSet();
$set->spawn(fn() => processFile("a.txt"));
$set->spawn(fn() => processFile("b.txt"));
$set->spawn(fn() => throw new \RuntimeException("error"));
$set->seal();
$set->awaitCompletion(); // Does not throw even if tasks failed
echo "All tasks completed\n";
});
See Also
- TaskSet::joinAll — Wait and get results
- TaskSet::finally — Completion handler