userver: userver/clients/http/response_future.hpp Source File
Loading...
Searching...
No Matches
response_future.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/clients/http/response_future.hpp
4/// @brief @copybrief clients::http::ResponseFuture
5
6#include <future>
7#include <memory>
8#include <type_traits>
9
10#include <userver/clients/http/config.hpp>
11#include <userver/clients/http/response.hpp>
12#include <userver/compiler/select.hpp>
13#include <userver/engine/deadline.hpp>
14#include <userver/engine/future.hpp>
15#include <userver/engine/impl/context_accessor.hpp>
16
17USERVER_NAMESPACE_BEGIN
18
19namespace clients::http {
20
21class RequestState;
22
23namespace impl {
24class EasyWrapper;
25} // namespace impl
26
27/// @brief Allows to perform a request concurrently with other work without
28/// creating an extra coroutine for waiting.
29class ResponseFuture final {
30public:
31 ResponseFuture(ResponseFuture&& other) noexcept;
32 ResponseFuture& operator=(ResponseFuture&&) noexcept;
33 ResponseFuture(const ResponseFuture&) = delete;
34 ResponseFuture& operator=(const ResponseFuture&) = delete;
35 ~ResponseFuture();
36
37 void Cancel();
38
39 void Detach();
40
41 std::future_status Wait();
42
43 std::shared_ptr<Response> Get();
44
45 void SetCancellationPolicy(CancellationPolicy cp);
46
47 /// @cond
48 /// Internal helper for WaitAny/WaitAll
49 engine::impl::ContextAccessor* TryGetContextAccessor() noexcept;
50
51 ResponseFuture(engine::Future<std::shared_ptr<Response>>&& future, std::shared_ptr<RequestState> request);
52 /// @endcond
53
54private:
55 void CancelOrDetach();
56
57 engine::Future<std::shared_ptr<Response>> future_;
58 engine::Deadline deadline_;
59 std::shared_ptr<RequestState> request_state_;
60 bool was_deadline_propagated_{false};
61 CancellationPolicy cancellation_policy_;
62};
63
64} // namespace clients::http
65
66USERVER_NAMESPACE_END