userver: userver/engine/task/shared_task_with_result.hpp Source File
Loading...
Searching...
No Matches
shared_task_with_result.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <memory>
7#include <stdexcept>
8#include <type_traits>
9#include <utility>
10
12#include <userver/engine/impl/task_context_holder.hpp>
16#include <userver/utils/impl/wrapped_call.hpp>
17
18USERVER_NAMESPACE_BEGIN
19
20namespace engine {
21
33template <typename T>
34class [[nodiscard]] SharedTaskWithResult : public SharedTask {
35public:
40
44
47
54
57 SharedTaskWithResult(SharedTaskWithResult&& other) noexcept = default;
58
65
74 decltype(auto) Get() const& noexcept(false) {
76
77 Wait();
78 if (GetState() == State::kCancelled) {
80 }
81
82 return utils::impl::CastWrappedCall<T>(GetPayload()).Get();
83 }
84
85 std::add_lvalue_reference<const T> Get() && {
86 static_assert(!sizeof(T*), "Store SharedTaskWithResult before using");
87 }
88
90 static constexpr WaitMode kWaitMode = WaitMode::kMultipleAwaiters;
91
92 // For internal use only.
93 explicit SharedTaskWithResult(impl::TaskContextHolder&& context)
94 : SharedTask(std::move(context))
95 {}
97};
98
99} // namespace engine
100
101USERVER_NAMESPACE_END