userver
C++ Async Framework
Toggle main menu visibility
Documentation
API Groups
Namespaces
Reference
Class List
Class Index
File List
Macros
All
e
i
l
r
t
u
Functions
Macros
e
i
l
r
t
u
Examples
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Modules
Pages
Concepts
Loading...
Searching...
No Matches
async.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/engine/async.hpp
4
/// @brief Low-level TaskWithResult creation helpers
5
6
#
include
<
userver
/
engine
/
deadline
.
hpp
>
7
#
include
<
userver
/
engine
/
impl
/
task_context_factory
.
hpp
>
8
#
include
<
userver
/
engine
/
task
/
shared_task_with_result
.
hpp
>
9
#
include
<
userver
/
engine
/
task
/
task_processor_fwd
.
hpp
>
10
#
include
<
userver
/
engine
/
task
/
task_with_result
.
hpp
>
11
#
include
<
userver
/
utils
/
impl
/
wrapped_call
.
hpp
>
12
13
USERVER_NAMESPACE_BEGIN
14
15
namespace
engine {
16
17
namespace
impl {
18
19
template
<
template
<
typename
>
typename
TaskType,
typename
Function,
typename
... Args>
20
[[nodiscard]]
auto
MakeTaskWithResult(
21
TaskProcessor& task_processor,
22
Task
::
Importance
importance,
23
Deadline deadline,
24
Function&& f,
25
Args&&... args
26
) {
27
using
ResultType =
typename
utils
::impl::WrappedCallImplType<Function, Args...>::ResultType;
28
constexpr
auto
kWaitMode = TaskType<ResultType>::kWaitMode;
29
30
return
TaskType<ResultType>{MakeTask(
31
{task_processor, importance, kWaitMode, deadline}, std::forward<Function>(f), std::forward<Args>(args)...
32
)};
33
}
34
35
}
// namespace impl
36
37
/// @brief Runs an asynchronous function call using the specified task processor.
38
///
39
/// @warning If any logs are written in the task function (outside any manual tracing::Span scopes),
40
/// then those logs will have no `span_id` (yikes!). **Prefer utils::Async by default instead.**
41
///
42
/// Also, some clients may call tracing::Span::CurrentSpan unconditionally, so don't be too surprised
43
/// if they won't work without a span scope. Do write tests.
44
///
45
/// `AsyncNoSpan` is useful for implementing periodic tasks (like utils::PeriodicTask), task pools,
46
/// and some low-level (e.g. driver) code where logs are definitely not written, or where `span_id` is useless.
47
///
48
/// @see utils::Async for main documentation on `Async` function family.
49
template
<
typename
Function,
typename
... Args>
50
[[nodiscard]]
auto
AsyncNoSpan
(TaskProcessor& task_processor, Function&& f, Args&&... args) {
51
return
impl::MakeTaskWithResult<
TaskWithResult
>(
52
task_processor,
Task
::
Importance
::
kNormal
, {}, std::forward<Function>(f), std::forward<Args>(args)...
53
);
54
}
50
[[nodiscard]]
auto
AsyncNoSpan
(TaskProcessor& task_processor, Function&& f, Args&&... args) {
…
}
55
56
/// @overload
57
template
<
typename
Function,
typename
... Args>
58
[[nodiscard]]
auto
SharedAsyncNoSpan
(TaskProcessor& task_processor, Function&& f, Args&&... args) {
59
return
impl::MakeTaskWithResult<
SharedTaskWithResult
>(
60
task_processor,
Task
::
Importance
::
kNormal
, {}, std::forward<Function>(f), std::forward<Args>(args)...
61
);
62
}
58
[[nodiscard]]
auto
SharedAsyncNoSpan
(TaskProcessor& task_processor, Function&& f, Args&&... args) {
…
}
63
64
/// @overload
65
template
<
typename
Function,
typename
... Args>
66
[[nodiscard]]
auto
AsyncNoSpan
(TaskProcessor& task_processor, Deadline deadline, Function&& f, Args&&... args) {
67
return
impl::MakeTaskWithResult<
TaskWithResult
>(
68
task_processor,
Task
::
Importance
::
kNormal
, deadline, std::forward<Function>(f), std::forward<Args>(args)...
69
);
70
}
66
[[nodiscard]]
auto
AsyncNoSpan
(TaskProcessor& task_processor, Deadline deadline, Function&& f, Args&&... args) {
…
}
71
72
/// @overload
73
template
<
typename
Function,
typename
... Args>
74
[[nodiscard]]
auto
SharedAsyncNoSpan
(TaskProcessor& task_processor, Deadline deadline, Function&& f, Args&&... args) {
75
return
impl::MakeTaskWithResult<
SharedTaskWithResult
>(
76
task_processor,
Task
::
Importance
::
kNormal
, deadline, std::forward<Function>(f), std::forward<Args>(args)...
77
);
78
}
74
[[nodiscard]]
auto
SharedAsyncNoSpan
(TaskProcessor& task_processor, Deadline deadline, Function&& f, Args&&... args) {
…
}
79
80
/// @overload
81
template
<
typename
Function,
typename
... Args>
82
[[nodiscard]]
auto
AsyncNoSpan
(Function&& f, Args&&... args) {
83
return
AsyncNoSpan(
current_task
::
GetTaskProcessor
(
)
, std::forward<Function>(f), std::forward<Args>(args)...);
84
}
82
[[nodiscard]]
auto
AsyncNoSpan
(Function&& f, Args&&... args) {
…
}
85
86
/// @overload
87
template
<
typename
Function,
typename
... Args>
88
[[nodiscard]]
auto
SharedAsyncNoSpan
(Function&& f, Args&&... args) {
89
return
SharedAsyncNoSpan(
current_task
::
GetTaskProcessor
(
)
, std::forward<Function>(f), std::forward<Args>(args)...);
90
}
88
[[nodiscard]]
auto
SharedAsyncNoSpan
(Function&& f, Args&&... args) {
…
}
91
92
/// @overload
93
template
<
typename
Function,
typename
... Args>
94
[[nodiscard]]
auto
AsyncNoSpan
(Deadline deadline, Function&& f, Args&&... args) {
95
return
AsyncNoSpan(
96
current_task
::
GetTaskProcessor
(
)
, deadline, std::forward<Function>(f), std::forward<Args>(args)...
97
);
98
}
94
[[nodiscard]]
auto
AsyncNoSpan
(Deadline deadline, Function&& f, Args&&... args) {
…
}
99
100
/// @overload
101
template
<
typename
Function,
typename
... Args>
102
[[nodiscard]]
auto
SharedAsyncNoSpan
(Deadline deadline, Function&& f, Args&&... args) {
103
return
SharedAsyncNoSpan(
104
current_task
::
GetTaskProcessor
(
)
, deadline, std::forward<Function>(f), std::forward<Args>(args)...
105
);
106
}
102
[[nodiscard]]
auto
SharedAsyncNoSpan
(Deadline deadline, Function&& f, Args&&... args) {
…
}
107
108
/// @overload
109
/// @see Task::Importance::Critical
110
template
<
typename
Function,
typename
... Args>
111
[[nodiscard]]
auto
CriticalAsyncNoSpan
(TaskProcessor& task_processor, Function&& f, Args&&... args) {
112
return
impl::MakeTaskWithResult<
TaskWithResult
>(
113
task_processor,
Task
::
Importance
::
kCritical
, {}, std::forward<Function>(f), std::forward<Args>(args)...
114
);
115
}
111
[[nodiscard]]
auto
CriticalAsyncNoSpan
(TaskProcessor& task_processor, Function&& f, Args&&... args) {
…
}
116
117
/// @overload
118
/// @see Task::Importance::Critical
119
template
<
typename
Function,
typename
... Args>
120
[[nodiscard]]
auto
SharedCriticalAsyncNoSpan
(TaskProcessor& task_processor, Function&& f, Args&&... args) {
121
return
impl::MakeTaskWithResult<
SharedTaskWithResult
>(
122
task_processor,
Task
::
Importance
::
kCritical
, {}, std::forward<Function>(f), std::forward<Args>(args)...
123
);
124
}
120
[[nodiscard]]
auto
SharedCriticalAsyncNoSpan
(TaskProcessor& task_processor, Function&& f, Args&&... args) {
…
}
125
126
/// @overload
127
/// @see Task::Importance::Critical
128
template
<
typename
Function,
typename
... Args>
129
[[nodiscard]]
auto
CriticalAsyncNoSpan
(Function&& f, Args&&... args) {
130
return
CriticalAsyncNoSpan(
131
current_task
::
GetTaskProcessor
(
)
, std::forward<Function>(f), std::forward<Args>(args)...
132
);
133
}
129
[[nodiscard]]
auto
CriticalAsyncNoSpan
(Function&& f, Args&&... args) {
…
}
134
135
/// @overload
136
/// @see Task::Importance::Critical
137
template
<
typename
Function,
typename
... Args>
138
[[nodiscard]]
auto
SharedCriticalAsyncNoSpan
(Function&& f, Args&&... args) {
139
return
SharedCriticalAsyncNoSpan(
140
current_task
::
GetTaskProcessor
(
)
, std::forward<Function>(f), std::forward<Args>(args)...
141
);
142
}
138
[[nodiscard]]
auto
SharedCriticalAsyncNoSpan
(Function&& f, Args&&... args) {
…
}
143
144
/// @overload
145
/// @see Task::Importance::Critical
146
template
<
typename
Function,
typename
... Args>
147
[[nodiscard]]
auto
CriticalAsyncNoSpan
(Deadline deadline, Function&& f, Args&&... args) {
148
return
impl::MakeTaskWithResult<
TaskWithResult
>(
149
current_task
::
GetTaskProcessor
(
)
,
150
Task
::
Importance
::
kCritical
,
151
deadline,
152
std::forward<Function>(f),
153
std::forward<Args>(args)...
154
);
155
}
147
[[nodiscard]]
auto
CriticalAsyncNoSpan
(Deadline deadline, Function&& f, Args&&... args) {
…
}
156
157
}
// namespace engine
158
159
USERVER_NAMESPACE_END
userver
engine
async.hpp
Generated on Thu Apr 24 2025 12:12:03 for userver by
Doxygen
1.13.2