Kraken\Promise\Promise::cancel PHP Метод

cancel() публичный Метод

public cancel ( $reason = null )
    public function cancel($reason = null)
    {
        if (null !== $this->result || $reason === $this) {
            return $this->result;
        }
        $target = $this;
        if (null !== $this->canceller) {
            $canceller = $this->canceller;
            $this->canceller = null;
            $target = $canceller($reason);
        }
        if ($target === $this) {
            return $target->settle(self::doCancel($reason));
        }
        return $target;
    }

Usage Example

 /**
  * @override
  * @inheritDoc
  */
 protected function command($params = [])
 {
     $runtime = $this->runtime;
     $promise = new Promise();
     $runtime->once('destroy', function () use($promise) {
         $promise->resolve('Runtime has been destroyed');
     });
     $runtime->destroy()->then(null, function ($ex) use($promise) {
         $promise->reject($ex);
     }, function ($ex) use($promise) {
         $promise->cancel($ex);
     });
     return $promise;
 }