Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Utils.php

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

Utils

Namespace

GuzzleHttp\Promise

Code

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);
    });
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal