function Utils::all
Given an array of promises, return a promise that is fulfilled when all the items in the array are fulfilled.
The promise's fulfillment value is an array with fulfillment values at respective positions to the original array. If any promise in the array rejects, the returned promise is rejected with the rejection reason.
Parameters
mixed $promises Promises or values.:
bool $recursive If true, resolves new promises that might have been added to the stack during its own resolution.:
File
-
vendor/
guzzlehttp/ promises/ src/ Utils.php, line 138
Class
Namespace
GuzzleHttp\PromiseCode
public static function all($promises, bool $recursive = false) : PromiseInterface {
$results = [];
$promise = Each::of($promises, function ($value, $idx) use (&$results) : void {
$results[$idx] = $value;
}, function ($reason, $idx, Promise $aggregate) : void {
if (Is::pending($aggregate)) {
$aggregate->reject($reason);
}
})
->then(function () use (&$results) {
ksort($results);
return $results;
});
if (true === $recursive) {
$promise = $promise->then(function ($results) use ($recursive, &$promises) {
foreach ($promises as $promise) {
if (Is::pending($promise)) {
return self::all($promises, $recursive);
}
}
return $results;
});
}
return $promise;
}