Exemplo n.º 1
0
 /**
  * Inform the coroutine that the executing strand is being terminated.
  *
  * @param StrandInterface $strand The strand that is executing the coroutine.
  */
 public function terminate(StrandInterface $strand)
 {
     $strand->emit('terminate', [$strand]);
     $strand->emit('exit', [$strand]);
     $strand->removeAllListeners();
     $strand->suspend();
 }
Exemplo n.º 2
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);
     });
 }
Exemplo n.º 3
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));
         }
     });
 }
Exemplo n.º 4
0
 /**
  * Suspend the strand until the next tick.
  *
  * @param StrandInterface $strand The currently executing strand.
  */
 public function cooperate(StrandInterface $strand)
 {
     $strand->suspend();
     $strand->kernel()->eventLoop()->futureTick(function () use($strand) {
         $strand->resumeWithValue(null);
     });
 }