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 {
30 public:
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,
52 std::shared_ptr<RequestState> request);
53 /// @endcond
54
55 private:
56 void CancelOrDetach();
57
58 engine::Future<std::shared_ptr<Response>> future_;
59 engine::Deadline deadline_;
60 std::shared_ptr<RequestState> request_state_;
61 bool was_deadline_propagated_{false};
62 CancellationPolicy cancellation_policy_;
63};
64
65} // namespace clients::http
66
67USERVER_NAMESPACE_END