You are here

public function Promise::cancel in Zircon Profile 8

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

Cancels the promise if possible.

@link https://github.com/promises-aplus/cancellation-spec/issues/7

Overrides PromiseInterface::cancel

File

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

Class

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

Namespace

GuzzleHttp\Promise

Code

public function cancel() {
  if ($this->state !== self::PENDING) {
    return;
  }
  $this->waitFn = $this->waitList = null;
  if ($this->cancelFn) {
    $fn = $this->cancelFn;
    $this->cancelFn = null;
    try {
      $fn();
    } catch (\Exception $e) {
      $this
        ->reject($e);
    }
  }

  // Reject the promise only if it wasn't rejected in a then callback.
  if ($this->state === self::PENDING) {
    $this
      ->reject(new CancellationException('Promise has been cancelled'));
  }
}