Exemple #1
0
 /**
  * @param PromiseInterface $promise
  * @return PromiseInterface
  */
 protected function send(PromiseInterface $promise)
 {
     $pid = $this->protocol->getPid();
     $origin = $this->protocol->getOrigin();
     $message = $this->message;
     $channel = $this->channel;
     if ($message instanceof Exception) {
         $answer = $channel->createProtocol($message->getMessage())->setPid($pid, true)->setException(get_class($message), true);
     } else {
         $answer = $channel->createProtocol($message)->setPid($pid, true);
     }
     $this->channel->send($origin, $answer, Channel::MODE_BUFFER_ONLINE);
     return $promise->resolve();
 }
Exemple #2
0
 /**
  * @return Error|Exception|string|null
  */
 public function reason()
 {
     return $this->isRejected() || $this->isCancelled() ? $this->result->reason() : null;
 }
Exemple #3
0
 /**
  * @param PromiseInterface $promise
  */
 protected function retry(PromiseInterface $promise)
 {
     if ($this->counter >= $this->params['retriesLimit']) {
         $promise->reject(new LazyException(new TimeoutException('No response was received during specified timeout.')));
     } else {
         if ($this->params['retriesInterval'] > 0) {
             $this->counter++;
             $this->channel->getLoop()->addTimer($this->params['retriesInterval'], function () use($promise) {
                 $this->send($promise);
             });
         } else {
             $this->counter++;
             $this->channel->getLoop()->afterTick(function () use($promise) {
                 $this->send($promise);
             });
         }
     }
 }