userver: /data/code/userver/libraries/grpc-proto-structs/include/userver/grpc-proto-structs/client/stream_read_future.hpp Source File
Loading...
Searching...
No Matches
stream_read_future.hpp
Go to the documentation of this file.
1#pragma once
2
5
8
9USERVER_NAMESPACE_BEGIN
10
11namespace grpc_proto_structs::client {
12
14template <typename StructsResponse>
15class StreamReadFuture final {
16public:
17 using ProtobufResponse = proto_structs::traits::CompatibleMessageType<StructsResponse>;
18 using ProtobufStreamFuture = ugrpc::client::StreamReadFuture<ProtobufResponse>;
19
20 StreamReadFuture(ProtobufStreamFuture&& future, ProtobufResponse& response)
21 : future_{std::move(future)},
22 response_(response)
23 {}
24
28 [[nodiscard]] bool IsReady() const noexcept { return future_.IsReady(); }
29
39 std::optional<StructsResponse> Get() {
40 if (future_.Get()) {
41 StructsResponse response;
42 proto_structs::MessageToStruct(response_, response);
43 return {response};
44 }
45 return std::nullopt;
46 }
47
48private:
49 ProtobufStreamFuture future_;
50 ProtobufResponse& response_;
51};
52
53} // namespace grpc_proto_structs::client
54
55USERVER_NAMESPACE_END