You are here

public function Promise::wait in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/guzzlehttp/promises/src/Promise.php \GuzzleHttp\Promise\Promise::wait()

Waits until the promise completes if possible.

Pass $unwrap as true to unwrap the result of the promise, either returning the resolved value or throwing the rejected exception.

If the promise cannot be waited on, then the promise will be rejected.

Parameters

bool $unwrap:

Return value

mixed

Throws

\LogicException if the promise has no wait function or if the promise does not settle after waiting.

Overrides PromiseInterface::wait

File

vendor/guzzlehttp/promises/src/Promise.php, line 60

Class

Promise
Promises/A+ implementation that avoids recursion when possible.

Namespace

GuzzleHttp\Promise

Code

public function wait($unwrap = true) {
  $this
    ->waitIfPending();
  if (!$unwrap) {
    return null;
  }
  if ($this->result instanceof PromiseInterface) {
    return $this->result
      ->wait($unwrap);
  }
  elseif ($this->state === self::FULFILLED) {
    return $this->result;
  }
  else {

    // It's rejected so "unwrap" and throw an exception.
    throw exception_for($this->result);
  }
}