Automattic\WooCommerce\Vendor\GraphQL\Executor\Promise\Adapter
SyncPromiseAdapter::all
Method of the class: SyncPromiseAdapter{}
No Hooks.
Returns
null. Nothing (null).
Usage
$SyncPromiseAdapter = new SyncPromiseAdapter(); $SyncPromiseAdapter->all( $promisesOrValues ): Promise;
- $promisesOrValues(iterable) (required)
- .
SyncPromiseAdapter::all() SyncPromiseAdapter::all code WC 10.9.1
public function all(iterable $promisesOrValues): Promise
{
$all = new SyncPromise();
$total = is_array($promisesOrValues)
? count($promisesOrValues)
: iterator_count($promisesOrValues);
$count = 0;
$result = [];
$resolveAllWhenFinished = function () use (&$count, &$total, $all, &$result): void {
if ($count === $total) {
$all->resolve($result);
}
};
foreach ($promisesOrValues as $index => $promiseOrValue) {
if ($promiseOrValue instanceof Promise) {
$result[$index] = null;
$promiseOrValue->then(
static function ($value) use (&$result, $index, &$count, &$resolveAllWhenFinished): void {
$result[$index] = $value;
++$count;
$resolveAllWhenFinished();
},
[$all, 'reject']
);
continue;
}
$result[$index] = $promiseOrValue;
++$count;
}
$resolveAllWhenFinished();
return new Promise($all, $this);
}