You are here

public static function DeferredUtility::waitAll in GraphQL 8.4

Ensures that all promises in the given array are resolved.

The input array may contain any combination of promise and non-promise values. If it does not contain any promises at all, it will simply return the original array unchanged.

Parameters

array $values: An array of promises and arbitrary values.

Return value

\GraphQL\Deferred|array The deferred result or the unchanged input array if it does not contain any promises.

1 call to DeferredUtility::waitAll()
DataProducerProxy::prepare in src/Plugin/GraphQL/DataProducer/DataProducerProxy.php
Instantiate the actual data producer and populate it with context values.

File

src/GraphQL/Utility/DeferredUtility.php, line 89

Class

DeferredUtility
Helper class for dealing with deferred promises.

Namespace

Drupal\graphql\GraphQL\Utility

Code

public static function waitAll(array $values) {
  if (static::containsDeferred($values)) {
    return new Deferred(function () use ($values) {
      $adapter = static::promiseAdapter();
      return $adapter
        ->all(array_map(function ($value) use ($adapter) {
        if ($value instanceof SyncPromise) {
          return $adapter
            ->convertThenable($value);
        }
        return $value;
      }, $values));
    });
  }
  return $values;
}