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)
 {
     $strand->suspend();
     $this->timer = $strand->kernel()->eventLoop()->addTimer($this->timeout, function () use($strand) {
         $strand->resumeWithValue(null);
     });
 }
Beispiel #2
0
 /**
  * Start the coroutine.
  *
  * @param StrandInterface $strand The strand that is executing the coroutine.
  */
 public function call(StrandInterface $strand)
 {
     $strand->suspend();
     $this->promise->then(function ($value) use($strand) {
         if ($this->promise) {
             $strand->resumeWithValue($value);
         }
     }, function ($reason) use($strand) {
         if ($this->promise) {
             $strand->resumeWithException($this->adaptReasonToException($reason));
         }
     });
 }
Beispiel #3
0
 /**
  * Start the coroutine.
  *
  * @param StrandInterface $strand The strand that is executing the coroutine.
  */
 public function call(StrandInterface $strand)
 {
     // If some of the strands have exited already, resume immediately ...
     if ($this->exited) {
         $strand->resumeWithValue($this->exited);
         return;
     }
     // Otherwise, suspend the current strand until at least one strand exits ...
     $this->strand = $strand;
     $this->strand->suspend();
     foreach ($this->substrands as $strand) {
         $strand->on('exit', [$this, 'onStrandExit']);
     }
 }
Beispiel #4
0
 /**
  * Execute a coroutine on its own strand.
  *
  * @param StrandInterface $strand    The currently executing strand.
  * @param mixed           $coroutine The coroutine to execute.
  */
 public function execute(StrandInterface $strand, $coroutine)
 {
     $substrand = $strand->kernel()->execute($coroutine);
     $strand->resumeWithValue($substrand);
 }