You are here

private function EachPromise::createPromise in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/guzzlehttp/promises/src/EachPromise.php \GuzzleHttp\Promise\EachPromise::createPromise()
1 call to EachPromise::createPromise()
EachPromise::promise in vendor/guzzlehttp/promises/src/EachPromise.php
Returns a promise.

File

vendor/guzzlehttp/promises/src/EachPromise.php, line 82

Class

EachPromise
Represents a promise that iterates over many promises and invokes side-effect functions in the process.

Namespace

GuzzleHttp\Promise

Code

private function createPromise() {
  $this->aggregate = new Promise(function () {
    reset($this->pending);

    // Consume a potentially fluctuating list of promises while
    // ensuring that indexes are maintained (precluding array_shift).
    while ($promise = current($this->pending)) {
      next($this->pending);
      $promise
        ->wait();
      if ($this->aggregate
        ->getState() !== PromiseInterface::PENDING) {
        return;
      }
    }
  });

  // Clear the references when the promise is resolved.
  $clearFn = function () {
    $this->iterable = $this->concurrency = $this->pending = null;
    $this->onFulfilled = $this->onRejected = null;
  };
  $this->aggregate
    ->then($clearFn, $clearFn);
}