userver
C++ Async Framework
Toggle main menu visibility
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
11
#include <
userver/engine/exception.hpp
>
12
#include <userver/engine/impl/task_context_holder.hpp>
13
#include <
userver/engine/task/shared_task.hpp
>
14
#include <
userver/engine/task/task_processor_fwd.hpp
>
15
#include <
userver/utils/assert.hpp
>
16
#include <userver/utils/impl/wrapped_call.hpp>
17
18
USERVER_NAMESPACE_BEGIN
19
20
namespace
engine
{
21
33
template
<
typename
T>
34
class
[[nodiscard]]
SharedTaskWithResult
:
public
SharedTask
{
35
public
:
39
SharedTaskWithResult
() =
default
;
40
43
~SharedTaskWithResult
() =
default
;
44
46
SharedTaskWithResult
(
const
SharedTaskWithResult
& other) =
default
;
47
53
SharedTaskWithResult
&
operator=
(
const
SharedTaskWithResult
& other) =
default
;
54
57
SharedTaskWithResult
(
SharedTaskWithResult
&& other)
noexcept
=
default
;
58
64
SharedTaskWithResult
&
operator=
(
SharedTaskWithResult
&& other)
noexcept
=
default
;
65
74
decltype
(
auto
)
Get
()
const
&
noexcept
(
false
) {
75
UASSERT
(
IsValid
());
76
77
Wait
();
78
if
(
GetState
() ==
State::kCancelled
) {
79
throw
TaskCancelledException
(
CancellationReason
());
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
101
USERVER_NAMESPACE_END
userver
engine
task
shared_task_with_result.hpp
Generated on
for userver by
Doxygen
1.17.0