You are here

public function Promise::cancel in Lockr 7.3

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 85

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 (\Throwable $e) {
      $this
        ->reject($e);
    } 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'));
  }
}