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

Breadcrumb

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

function any

Returns a promise that will resolve when any one of the items in `$promisesOrValues` resolves. The resolution value of the returned promise will be the resolution value of the triggering item.

The returned promise will only reject if *all* items in `$promisesOrValues` are rejected. The rejection value will be an array of all rejection reasons.

The returned promise will also reject with a `React\Promise\Exception\LengthException` if `$promisesOrValues` contains 0 items.

@template T

Parameters

iterable<PromiseInterface<T>|T> $promisesOrValues:

Return value

PromiseInterface<T>

9 string references to 'any'
ContextDefinition::dataTypeMatches in core/lib/Drupal/Core/Plugin/Context/ContextDefinition.php
Checks if this definition's data type matches that of the given context.
DataDefinition::getDataType in core/lib/Drupal/Core/TypedData/DataDefinition.php
Returns the data type of the data.
FloatItem::fieldSettingsForm in core/lib/Drupal/Core/Field/Plugin/Field/FieldType/FloatItem.php
Returns a form for the field-level settings.
ListDataDefinition::createFromDataType in core/lib/Drupal/Core/TypedData/ListDataDefinition.php
Creates a new data definition object.
ListFloatItem::storageSettingsForm in core/modules/options/src/Plugin/Field/FieldType/ListFloatItem.php
Returns a form for the storage-level settings.

... See full list

File

vendor/react/promise/src/functions.php, line 167

Namespace

React\Promise

Code

function any(iterable $promisesOrValues) : PromiseInterface {
    $cancellationQueue = new Internal\CancellationQueue();
    
    /** @var Promise<T> */
    return new Promise(function (callable $resolve, callable $reject) use ($promisesOrValues, $cancellationQueue) : void {
        $toReject = 0;
        $continue = true;
        $reasons = [];
        foreach ($promisesOrValues as $i => $promiseOrValue) {
            $cancellationQueue->enqueue($promiseOrValue);
            ++$toReject;
            resolve($promiseOrValue)->then(function ($value) use ($resolve, &$continue) : void {
                $continue = false;
                $resolve($value);
            }, function (\Throwable $reason) use ($i, &$reasons, &$toReject, $reject, &$continue) : void {
                $reasons[$i] = $reason;
                if (0 === --$toReject && !$continue) {
                    $reject(new CompositeException($reasons, 'All promises rejected.'));
                }
            });
            if (!$continue && !\is_array($promisesOrValues)) {
                break;
            }
        }
        $continue = false;
        if ($toReject === 0 && !$reasons) {
            $reject(new Exception\LengthException('Must contain at least 1 item but contains only 0 items.'));
        }
        elseif ($toReject === 0) {
            $reject(new CompositeException($reasons, 'All promises rejected.'));
        }
    }, $cancellationQueue);
}
RSS feed
Powered by Drupal