Github   Telegram
Loading...
Searching...
No Matches
async.hpp
Go to the documentation of this file.
1#pragma once
2
5
7#include <userver/engine/impl/task_context_factory.hpp>
12
13USERVER_NAMESPACE_BEGIN
14
15namespace engine {
16
17namespace impl {
18
19template <template <typename> typename TaskType, typename Function,
20 typename... Args>
21[[nodiscard]] auto MakeTaskWithResult(TaskProcessor& task_processor,
22 Task::Importance importance,
23 Deadline deadline, Function&& f,
24 Args&&... args) {
25 using ResultType =
26 typename utils::impl::WrappedCallImplType<Function, Args...>::ResultType;
27 constexpr auto kWaitMode = TaskType<ResultType>::kWaitMode;
28
29 return TaskType<ResultType>{
30 MakeTask({task_processor, importance, kWaitMode, deadline},
31 std::forward<Function>(f), std::forward<Args>(args)...)};
32}
33
34} // namespace impl
35
37template <typename Function, typename... Args>
38[[nodiscard]] auto AsyncNoSpan(TaskProcessor& task_processor, Function&& f,
39 Args&&... args) {
40 return impl::MakeTaskWithResult<TaskWithResult>(
41 task_processor, Task::Importance::kNormal, {}, std::forward<Function>(f),
42 std::forward<Args>(args)...);
43}
44
46template <typename Function, typename... Args>
47[[nodiscard]] auto SharedAsyncNoSpan(TaskProcessor& task_processor,
48 Function&& f, Args&&... args) {
49 return impl::MakeTaskWithResult<SharedTaskWithResult>(
50 task_processor, Task::Importance::kNormal, {}, std::forward<Function>(f),
51 std::forward<Args>(args)...);
52}
53
56template <typename Function, typename... Args>
57[[nodiscard]] auto AsyncNoSpan(TaskProcessor& task_processor, Deadline deadline,
58 Function&& f, Args&&... args) {
59 return impl::MakeTaskWithResult<TaskWithResult>(
60 task_processor, Task::Importance::kNormal, deadline,
61 std::forward<Function>(f), std::forward<Args>(args)...);
62}
63
66template <typename Function, typename... Args>
67[[nodiscard]] auto SharedAsyncNoSpan(TaskProcessor& task_processor,
68 Deadline deadline, Function&& f,
69 Args&&... args) {
70 return impl::MakeTaskWithResult<SharedTaskWithResult>(
71 task_processor, Task::Importance::kNormal, deadline,
72 std::forward<Function>(f), std::forward<Args>(args)...);
73}
74
76template <typename Function, typename... Args>
77[[nodiscard]] auto AsyncNoSpan(Function&& f, Args&&... args) {
78 return AsyncNoSpan(current_task::GetTaskProcessor(),
79 std::forward<Function>(f), std::forward<Args>(args)...);
80}
81
83template <typename Function, typename... Args>
84[[nodiscard]] auto SharedAsyncNoSpan(Function&& f, Args&&... args) {
85 return SharedAsyncNoSpan(current_task::GetTaskProcessor(),
86 std::forward<Function>(f),
87 std::forward<Args>(args)...);
88}
89
92template <typename Function, typename... Args>
93[[nodiscard]] auto AsyncNoSpan(Deadline deadline, Function&& f,
94 Args&&... args) {
95 return AsyncNoSpan(current_task::GetTaskProcessor(), deadline,
96 std::forward<Function>(f), std::forward<Args>(args)...);
97}
98
101template <typename Function, typename... Args>
102[[nodiscard]] auto SharedAsyncNoSpan(Deadline deadline, Function&& f,
103 Args&&... args) {
104 return SharedAsyncNoSpan(current_task::GetTaskProcessor(), deadline,
105 std::forward<Function>(f),
106 std::forward<Args>(args)...);
107}
108
112template <typename Function, typename... Args>
113[[nodiscard]] auto CriticalAsyncNoSpan(TaskProcessor& task_processor,
114 Function&& f, Args&&... args) {
115 return impl::MakeTaskWithResult<TaskWithResult>(
116 task_processor, Task::Importance::kCritical, {},
117 std::forward<Function>(f), std::forward<Args>(args)...);
118}
119
123template <typename Function, typename... Args>
124[[nodiscard]] auto SharedCriticalAsyncNoSpan(TaskProcessor& task_processor,
125 Function&& f, Args&&... args) {
126 return impl::MakeTaskWithResult<SharedTaskWithResult>(
127 task_processor, Task::Importance::kCritical, {},
128 std::forward<Function>(f), std::forward<Args>(args)...);
129}
130
134template <typename Function, typename... Args>
135[[nodiscard]] auto CriticalAsyncNoSpan(Function&& f, Args&&... args) {
136 return CriticalAsyncNoSpan(current_task::GetTaskProcessor(),
137 std::forward<Function>(f),
138 std::forward<Args>(args)...);
139}
140
144template <typename Function, typename... Args>
145[[nodiscard]] auto SharedCriticalAsyncNoSpan(Function&& f, Args&&... args) {
146 return SharedCriticalAsyncNoSpan(current_task::GetTaskProcessor(),
147 std::forward<Function>(f),
148 std::forward<Args>(args)...);
149}
150
154template <typename Function, typename... Args>
155[[nodiscard]] auto CriticalAsyncNoSpan(Deadline deadline, Function&& f,
156 Args&&... args) {
157 return impl::MakeTaskWithResult<TaskWithResult>(
158 current_task::GetTaskProcessor(), Task::Importance::kCritical, deadline,
159 std::forward<Function>(f), std::forward<Args>(args)...);
160}
161
162} // namespace engine
163
164USERVER_NAMESPACE_END