You are here

private function EachPromise::createPromise in Lockr 7.3

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 87

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->mutex = false;
  $this->aggregate = new Promise(function () {
    reset($this->pending);
    if (empty($this->pending) && !$this->iterable
      ->valid()) {
      $this->aggregate
        ->resolve(null);
      return;
    }

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