userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
response_future.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file
4
/// @brief Structs future wrapper over Vanilla ResponseFufure.
5
6
#
include
<
userver
/
compiler
/
impl
/
lifetime
.
hpp
>
7
#
include
<
userver
/
proto
-
structs
/
convert
.
hpp
>
8
#
include
<
userver
/
ugrpc
/
client
/
response_future
.
hpp
>
9
#
include
<
userver
/
ugrpc
/
client
/
stream
.
hpp
>
10
11
USERVER_NAMESPACE_BEGIN
12
13
namespace
grpc_proto_structs::client {
14
15
/// @brief proto-struct response future.
16
template
<
typename
Response>
17
class
ResponseFuture final {
18
public
:
19
using
VanillaResponse = proto_structs::traits::CompatibleMessageType<Response>;
20
using
VanillaFuture = ugrpc::client::ResponseFuture<VanillaResponse>;
21
22
explicit
ResponseFuture(VanillaFuture&& future)
23
: future_{std::move(future)}
24
{}
25
26
/// @brief Checks if the asynchronous call has completed.
27
/// Note, that once user gets result, IsReady should not be called.
28
/// @return true if result ready.
29
[[nodiscard]]
bool
IsReady
()
const
{
return
future_.IsReady(); }
30
31
/// @brief Await response until specified timepoint.
32
///
33
/// @throws ugrpc::client::RpcError on an RPC error.
34
[[nodiscard]]
engine
::
FutureStatus
WaitUntil
(
engine
::
Deadline
deadline
)
const
noexcept
{
35
return
future_.WaitUntil(deadline);
36
}
37
38
/// @brief Await and read the response.
39
///
40
/// `Get` should not be called multiple times for the same UnaryFuture.
41
///
42
/// The connection is not closed, it will be reused for new RPCs.
43
///
44
/// @returns the response on success.
45
/// @throws ugrpc::client::RpcError on an RPC error.
46
/// @throws ugrpc::client::RpcCancelledError on task cancellation.
47
Response
Get
() {
return
proto_structs::MessageToStruct<Response>(future_.Get()); }
48
49
/// @brief Cancel call.
50
void
Cancel
() {
return
future_.Cancel(); }
51
52
/// @brief Get call context, useful e.g. for accessing metadata.
53
ugrpc
::
client
::
CallContext
&
GetContext
() {
return
future_.GetContext(); }
54
55
/// @overload
56
const
ugrpc
::
client
::
CallContext
&
GetContext
()
const
{
return
future_.GetContext(); }
57
58
/// Satisfies @ref engine::Awaitable, for use with @ref engine::WaitAnyContext and friends.
59
engine
::
AwaitableToken
GetAwaitableToken
()
noexcept
USERVER_IMPL_LIFETIME_BOUND {
60
return
future_.GetAwaitableToken();
61
}
62
63
private
:
64
VanillaFuture future_;
65
};
66
67
}
// namespace grpc_proto_structs::client
68
69
USERVER_NAMESPACE_END
grpc-proto-structs
include
userver
grpc-proto-structs
client
response_future.hpp
Generated on
for userver by
Doxygen
1.17.0