6 #ifndef IROHA_ASYNC_GRPC_CLIENT_HPP 7 #define IROHA_ASYNC_GRPC_CLIENT_HPP 12 #include <google/protobuf/empty.pb.h> 13 #include <grpc++/grpc++.h> 14 #include <grpcpp/impl/codegen/async_unary_call.h> 24 template <
typename Response>
25 class AsyncGrpcClient {
29 log_(
std::move(log)) {}
37 while (
cq_.Next(&got_tag, &ok)) {
39 if (not call->status.ok()) {
40 log_->warn(
"RPC failed: {} {}",
42 call->status.error_message());
44 if (call->on_response) {
45 call->on_response(call->status, call->reply);
58 grpc::CompletionQueue
cq_;
71 std::unique_ptr<grpc::ClientAsyncResponseReaderInterface<Response>>
88 call->response_reader = lambda(&call->context, &cq_);
89 call->response_reader->Finish(&call->reply, &call->status, call);
98 #endif // IROHA_ASYNC_GRPC_CLIENT_HPP grpc::ClientContext context
Definition: async_grpc_client.hpp:67
AsyncGrpcClient(logger::LoggerPtr log)
Definition: async_grpc_client.hpp:27
Definition: async_grpc_client.hpp:64
Response reply
Definition: async_grpc_client.hpp:65
std::unique_ptr< grpc::ClientAsyncResponseReaderInterface< Response > > response_reader
Definition: async_grpc_client.hpp:72
std::function< void(grpc::Status &, Response &)> on_response
Definition: async_grpc_client.hpp:74
void asyncCompleteRpc()
Definition: async_grpc_client.hpp:34
std::shared_ptr< Logger > LoggerPtr
Definition: logger_fwd.hpp:22
grpc::Status status
Definition: async_grpc_client.hpp:69
Definition: block_query.hpp:15
std::thread thread_
Definition: async_grpc_client.hpp:59
Definition: application.hpp:53
Status
Definition: status.hpp:12
~AsyncGrpcClient()
Definition: async_grpc_client.hpp:51
void Call(F &&lambda, std::function< void(grpc::Status &, Response &)> on_response={})
Definition: async_grpc_client.hpp:83
grpc::CompletionQueue cq_
Definition: async_grpc_client.hpp:58