userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
stream_read_future.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file
4
/// @brief @copybrief grpc_proto_structs::client::StreamReadFuture
5
6
#
include
<
userver
/
proto
-
structs
/
convert
.
hpp
>
7
#
include
<
userver
/
ugrpc
/
client
/
stream_read_future
.
hpp
>
8
9
USERVER_NAMESPACE_BEGIN
10
11
namespace
grpc_proto_structs::client {
12
13
/// @brief proto-struct stream response future.
14
template
<
typename
StructsResponse>
15
class
StreamReadFuture final {
16
public
:
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
25
/// @brief Checks if the asynchronous call has completed
26
/// Note, that once user gets result, IsReady should not be called
27
/// @return true if result ready
28
[[nodiscard]]
bool
IsReady
()
const
noexcept
{
return
future_.IsReady(); }
29
30
/// @brief Await response
31
///
32
/// Upon completion the result is available in `response` that was
33
/// specified when initiating the asynchronous read
34
///
35
/// `Get` should not be called multiple times for the same StreamReadFuture.
36
///
37
/// @throws ugrpc::client::RpcError on an RPC error
38
/// @throws ugrpc::client::RpcCancelledError on task cancellation
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
48
private
:
49
ProtobufStreamFuture future_;
50
ProtobufResponse& response_;
51
};
52
53
}
// namespace grpc_proto_structs::client
54
55
USERVER_NAMESPACE_END
grpc-proto-structs
include
userver
grpc-proto-structs
client
stream_read_future.hpp
Generated on
for userver by
Doxygen
1.17.0