fiber-interop

fiber\await_all()

Wait for every awaitable; results keep their keys.

function fiber\await_all(array $awaitables, float $timeout = PHP_FLOAT_MAX): array

Behaviour

All awaitables are allowed to settle, then the first exception (in key order) is rethrown. The timeout covers the whole call; on expiry a TimeoutException is thrown and the tasks keep running.

Example

Source: examples/api/await_all.php. Run on phasync and Revolt; the output is identical.

<?php
require __DIR__ . '/vendor/autoload.php';
use function fiber\{run, go, await_all, sleep};
run(function () {
    $t = microtime(true);
    $r = await_all(['a' => go(function () { sleep(0.2); return 1; }), 'b' => go(function () { sleep(0.2); return 2; })]);
    echo json_encode($r), ' in ', round(microtime(true) - $t, 1), " s\n";
});

All functions