/** * Send the request using passed Promise. * * @param PromiseInterface $promise * @return PromiseInterface * @resolves mixed * @rejects Error|Exception|string|null * @cancels Error|Exception|string|null */ protected function send(PromiseInterface $promise) { $pid = $this->protocol->getPid(); $origin = $this->protocol->getOrigin(); $message = $this->message; $channel = $this->channel; if ($message instanceof Error || $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(); }
/** * @param PromiseInterface $promise */ private function retry(PromiseInterface $promise) { if ($this->counter >= $this->params['retriesLimit']) { $promise->reject(new ThrowableProxy(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()->onTick(function () use($promise) { $this->send($promise); }); } } }
/** * Return rejection or cancellation reason for Promise. * * @return Error|Exception|string|null */ protected function getReason() { return $this->isRejected() || $this->isCancelled() ? $this->result->getReason() : null; }