ComponentsTaskSet::awaitCompletion

TaskSet::awaitCompletion ​

(PHP 8.6+, True Async 1.0)

php
public TaskSet::awaitCompletion(): void

Suspends the current coroutine until all tasks in the set are completed.

The set must be closed 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 closed.

Examples ​

Example #1 Waiting for completion ​

php
<?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->close();
    $set->awaitCompletion(Async\timeout(5000)); // Does not throw even if tasks failed

    echo "All tasks completed\n";
});

See Also ​