function Utils::some
Initiate a competitive race between multiple promises or values (values will become immediately fulfilled promises).
When count amount of promises have been fulfilled, the returned promise is fulfilled with an array that contains the fulfillment values of the winners in order of resolution.
This promise is rejected with a {of fulfilled promises is less than the desired $count.
Parameters
int $count Total number of promises.:
mixed $promises Promises or values.:
See also
AggregateException} if the number
File
-
vendor/
guzzlehttp/ promises/ src/ Utils.php, line 186
Class
Namespace
GuzzleHttp\PromiseCode
public static function some(int $count, $promises) : PromiseInterface {
$results = [];
$rejections = [];
return Each::of($promises, function ($value, $idx, PromiseInterface $p) use (&$results, $count) : void {
if (Is::settled($p)) {
return;
}
$results[$idx] = $value;
if (count($results) >= $count) {
$p->resolve(null);
}
}, function ($reason) use (&$rejections) : void {
$rejections[] = $reason;
})
->then(function () use (&$results, &$rejections, $count) {
if (count($results) !== $count) {
throw new AggregateException('Not enough promises to fulfill count', $rejections);
}
ksort($results);
return array_values($results);
});
}