/** * 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 ProtocolInterface $protocol * @return bool */ protected function handleReceiveResponse(ProtocolInterface $protocol) { $pid = $protocol->getPid(); if (!$this->existsRequest($pid)) { return false; } $message = $protocol->getMessage(); $exception = $protocol->getException(); if ($exception === '') { $this->resolveRequest($pid, $message); } else { if ($exception === TaskIncompleteException::class) { $this->cancelRequest($pid, new ThrowableProxy([$exception, $message])); } else { $this->rejectRequest($pid, new ThrowableProxy([$exception, $message])); } } return true; }
/** * @param string $name * @param ProtocolInterface $protocol * @return bool */ public function __invoke($name, ProtocolInterface $protocol) { return $protocol->getPid() === $this->pid; }