From e8dda6b4ca664074e87c917ddb7f195e1696cc28 Mon Sep 17 00:00:00 2001 From: Anton Zhilin Date: Sun, 29 Dec 2024 00:42:52 +0300 Subject: [PATCH] fix grpc: migrate to new unary RPC API for clients (#52) --- src/hello.cpp | 2 +- src/hello_client.cpp | 16 ++-------------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/src/hello.cpp b/src/hello.cpp index ccf1d24..f4bb32d 100644 --- a/src/hello.cpp +++ b/src/hello.cpp @@ -46,7 +46,7 @@ std::string SayHelloTo(std::string_view name, UserType type) { return fmt::format("Hi again, {}!\n", name); } - UASSERT(false); + UINVARIANT(false, "Invalid user type"); } void AppendHello(userver::components::ComponentList& component_list) { diff --git a/src/hello_client.cpp b/src/hello_client.cpp index 17fbf7f..2aa4b3c 100644 --- a/src/hello_client.cpp +++ b/src/hello_client.cpp @@ -10,20 +10,8 @@ std::string HelloClient::SayHello(std::string name) { handlers::api::HelloRequest request; request.set_name(std::move(name)); - // Deadline must be set manually for each RPC - auto context = std::make_unique(); - context->set_deadline( - userver::engine::Deadline::FromDuration(std::chrono::seconds{20})); - - // Initiate the RPC. No actual actions have been taken thus far besides - // preparing to send the request. - auto stream = client_.SayHello(request, std::move(context)); - - // Complete the unary RPC by sending the request and receiving the response. - // The client should call `Finish` (in case of single response) or `Read` - // until `false` (in case of response stream), otherwise the RPC will be - // cancelled. - handlers::api::HelloResponse response = stream.Finish(); + // Perform RPC by sending the request and receiving the response. + auto response = client_.SayHello(request); return std::move(*response.mutable_text()); }