Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function cancel(Throwable $reason = null)
 {
     if (null === $reason) {
         $reason = new TerminatedException();
     }
     if (null !== $this->generator) {
         try {
             do {
                 if ($this->current instanceof Awaitable) {
                     $this->current->cancel($reason);
                 }
                 $this->current = $this->generator->throw($reason);
             } while ($this->generator->valid());
         } catch (Throwable $exception) {
             $reason = $exception;
         }
     }
     parent::cancel($reason);
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function cancel(Throwable $reason = null)
 {
     if (!$this->isPending()) {
         return;
     }
     if (null === $reason) {
         $reason = new TerminatedException();
     }
     parent::cancel($reason);
     if ($this->current instanceof Awaitable) {
         $this->current->cancel($reason);
         // Will continue execution by throwing into the generator.
     }
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function cancel($reason = null)
 {
     if (null !== $this->generator) {
         $current = $this->generator->current();
         // Get last yielded value.
         if ($current instanceof Awaitable) {
             $current->cancel($reason);
             // Cancel last yielded awaitable.
         }
         try {
             $this->close();
             // Throwing finally blocks in the Generator may cause close() to throw.
         } catch (Throwable $exception) {
             $reason = $exception;
         }
     }
     parent::cancel($reason);
 }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  */
 public function cancel(Throwable $reason = null)
 {
     if (null === $reason) {
         $reason = new TerminatedException();
     }
     if ($this->current instanceof Awaitable) {
         $this->current->cancel($reason);
     }
     try {
         $this->generator = null;
         // finally blocks may throw from force-closed Generator.
     } catch (Throwable $exception) {
         $reason = $exception;
     }
     parent::cancel($reason);
 }