Beispiel #1
0
 /**
  * Invoked when tick() is called for the first time.
  *
  * @param StrandInterface $strand The strand that is executing the coroutine.
  */
 public function call(StrandInterface $strand)
 {
     $this->timer = $strand->kernel()->eventLoop()->addTimer($this->timeout, function () use($strand) {
         $this->timer = null;
         $strand->terminate();
     });
     $strand->call($this->coroutine);
 }
Beispiel #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);
     }
 }