Exemplo n.º 1
0
 /**
  * Return a value to the calling coroutine.
  *
  * @param StrandInterface $strand The currently executing strand.
  * @param mixed           $value  The value to send to the calling coroutine.
  */
 public function return_(StrandInterface $strand, $value = null)
 {
     $strand->returnValue($value);
 }
Exemplo n.º 2
0
 /**
  * Resume execution of a suspended coroutine by passing it an exception.
  *
  * @param StrandInterface $strand    The strand that is executing the coroutine.
  * @param Exception       $exception The exception to send to the coroutine.
  */
 public function resumeWithException(StrandInterface $strand, Exception $exception)
 {
     try {
         $this->generator->throw($exception);
         $valid = $this->generator->valid();
     } catch (Exception $e) {
         $strand->throwException($e);
         return;
     }
     if ($valid) {
         $strand->call($this->generator->current());
     } elseif (self::$hasReturnValue) {
         $strand->returnValue($this->generator->getReturn());
     } else {
         $strand->returnValue(null);
     }
 }
Exemplo n.º 3
0
 /**
  * Resume execution of a suspended coroutine by passing it a value.
  *
  * @param StrandInterface $strand The strand that is executing the coroutine.
  * @param mixed           $value  The value to send to the coroutine.
  */
 public function resumeWithValue(StrandInterface $strand, $value)
 {
     $strand->returnValue($value);
 }