userver: userver/ugrpc/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
3/// @file userver/ugrpc/client/stream_read_future.hpp
4/// @brief @copybrief ugrpc::client::StreamReadFuture
5
6#include <memory>
7#include <utility>
8
9#include <userver/ugrpc/client/impl/stream_read_future_impl_base.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace ugrpc::client {
14
15/// @brief StreamReadFuture for waiting a single read response from stream
16template <typename Response>
17class [[nodiscard]] StreamReadFuture {
18public:
19 StreamReadFuture(StreamReadFuture&&) noexcept = default;
20 StreamReadFuture& operator=(StreamReadFuture&&) noexcept = default;
21
22 /// @brief Checks if the asynchronous call has completed
23 /// Note, that once user gets result, IsReady should not be called
24 /// @return true if result ready
25 [[nodiscard]] bool IsReady() const { return impl_->IsReady(); }
26
27 /// @brief Await response
28 ///
29 /// Upon completion the result is available in `response` that was
30 /// specified when initiating the asynchronous read
31 ///
32 /// `Get` should not be called multiple times for the same StreamReadFuture.
33 ///
34 /// @throws ugrpc::client::RpcError on an RPC error
35 /// @throws ugrpc::client::RpcCancelledError on task cancellation
36 bool Get() { return impl_->Get(); }
37
38 /// @cond
39 // For internal use only
40 explicit StreamReadFuture(std::unique_ptr<impl::StreamReadFutureImplBase<Response>> impl) noexcept
41 : impl_{std::move(impl)}
42 {}
43 /// @endcond
44
45private:
46 std::unique_ptr<impl::StreamReadFutureImplBase<Response>> impl_;
47};
48
49} // namespace ugrpc::client
50
51USERVER_NAMESPACE_END