88#include < userver/engine/task/shared_task_with_result.hpp>
99#include < userver/engine/task/task_processor_fwd.hpp>
1010#include < userver/engine/task/task_with_result.hpp>
11- #include < userver/utils/impl/wrapped_call.hpp>
1211
1312USERVER_NAMESPACE_BEGIN
1413
1514namespace engine {
1615
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},
32- std::forward<Function>(f),
33- std::forward<Args>(args)...
34- )};
35- }
36-
37- } // namespace impl
38-
3916// / @brief Runs an asynchronous function call using the specified task processor.
4017// /
4118// / @warning If any logs are written in the task function (outside any manual tracing::Span scopes),
4219// / then those logs will have no `span_id` (yikes!).
4320// / If you create a span there manually, it will be disconnected from the outside trace.
4421// / **Prefer utils::Async by default instead.**
4522// /
46- // / @warning To hide a spammy span from traces, use @ref tracing::Span::CurrentSpan plus
47- // / @ref tracing::Span::SetLogLevel instead.
23+ // / @warning To hide a spammy span from traces, use @ref engine::TaskBuilder
24+ // / with @ref engine::TaskBuilder::HideSpan instead.
4825// / Logs will then be linked to the nearest span that is written out.
4926// /
5027// / @warning Some clients may call tracing::Span::CurrentSpan unconditionally, so don't be too surprised
@@ -56,49 +33,12 @@ template <template <typename> typename TaskType, typename Function, typename...
5633// / * some low-level (e.g. driver or filesystem-IO) code where logs are definitely not written;
5734// / * breaking traces e.g. this is (rarely) wanted for some background tasks.
5835// /
59- // / @see utils::Async for main documentation on `Async` function family.
36+ // / @see @ref utils::Async for main documentation on `Async` function family.
37+ // / @see @ref engine::TaskBuilder for more `Async` variants.
6038template <typename Function, typename ... Args>
6139[[nodiscard]] auto AsyncNoSpan (TaskProcessor& task_processor, Function&& f, Args&&... args) {
6240 return impl::MakeTaskWithResult<TaskWithResult>(
63- task_processor,
64- Task::Importance::kNormal ,
65- {},
66- std::forward<Function>(f),
67- std::forward<Args>(args)...
68- );
69- }
70-
71- // / @overload
72- template <typename Function, typename ... Args>
73- [[nodiscard]] auto SharedAsyncNoSpan (TaskProcessor& task_processor, Function&& f, Args&&... args) {
74- return impl::MakeTaskWithResult<SharedTaskWithResult>(
75- task_processor,
76- Task::Importance::kNormal ,
77- {},
78- std::forward<Function>(f),
79- std::forward<Args>(args)...
80- );
81- }
82-
83- // / @overload
84- template <typename Function, typename ... Args>
85- [[nodiscard]] auto AsyncNoSpan (TaskProcessor& task_processor, Deadline deadline, Function&& f, Args&&... args) {
86- return impl::MakeTaskWithResult<TaskWithResult>(
87- task_processor,
88- Task::Importance::kNormal ,
89- deadline,
90- std::forward<Function>(f),
91- std::forward<Args>(args)...
92- );
93- }
94-
95- // / @overload
96- template <typename Function, typename ... Args>
97- [[nodiscard]] auto SharedAsyncNoSpan (TaskProcessor& task_processor, Deadline deadline, Function&& f, Args&&... args) {
98- return impl::MakeTaskWithResult<SharedTaskWithResult>(
99- task_processor,
100- Task::Importance::kNormal ,
101- deadline,
41+ impl::TaskConfig{.task_processor = &task_processor},
10242 std::forward<Function>(f),
10343 std::forward<Args>(args)...
10444 );
@@ -107,58 +47,19 @@ template <typename Function, typename... Args>
10747// / @overload
10848template <typename Function, typename ... Args>
10949[[nodiscard]] auto AsyncNoSpan (Function&& f, Args&&... args) {
110- return AsyncNoSpan (current_task::GetTaskProcessor (), std::forward<Function>(f), std::forward<Args>(args)...);
111- }
112-
113- // / @overload
114- template <typename Function, typename ... Args>
115- [[nodiscard]] auto SharedAsyncNoSpan (Function&& f, Args&&... args) {
116- return SharedAsyncNoSpan (current_task::GetTaskProcessor (), std::forward<Function>(f), std::forward<Args>(args)...);
117- }
118-
119- // / @overload
120- template <typename Function, typename ... Args>
121- [[nodiscard]] auto AsyncNoSpan (Deadline deadline, Function&& f, Args&&... args) {
122- return AsyncNoSpan (
123- current_task::GetTaskProcessor (),
124- deadline,
125- std::forward<Function>(f),
126- std::forward<Args>(args)...
127- );
128- }
129-
130- // / @overload
131- template <typename Function, typename ... Args>
132- [[nodiscard]] auto SharedAsyncNoSpan (Deadline deadline, Function&& f, Args&&... args) {
133- return SharedAsyncNoSpan (
134- current_task::GetTaskProcessor (),
135- deadline,
136- std::forward<Function>(f),
137- std::forward<Args>(args)...
138- );
50+ return impl::MakeTaskWithResult<
51+ TaskWithResult>(impl::TaskConfig{}, std::forward<Function>(f), std::forward<Args>(args)...);
13952}
14053
14154// / @overload
14255// / @see Task::Importance::Critical
14356template <typename Function, typename ... Args>
14457[[nodiscard]] auto CriticalAsyncNoSpan (TaskProcessor& task_processor, Function&& f, Args&&... args) {
14558 return impl::MakeTaskWithResult<TaskWithResult>(
146- task_processor,
147- Task::Importance::kCritical ,
148- {},
149- std::forward<Function>(f),
150- std::forward<Args>(args)...
151- );
152- }
153-
154- // / @overload
155- // / @see Task::Importance::Critical
156- template <typename Function, typename ... Args>
157- [[nodiscard]] auto SharedCriticalAsyncNoSpan (TaskProcessor& task_processor, Function&& f, Args&&... args) {
158- return impl::MakeTaskWithResult<SharedTaskWithResult>(
159- task_processor,
160- Task::Importance::kCritical ,
161- {},
59+ impl::TaskConfig{
60+ .task_processor = &task_processor,
61+ .importance = Task::Importance::kCritical ,
62+ },
16263 std::forward<Function>(f),
16364 std::forward<Args>(args)...
16465 );
@@ -168,32 +69,8 @@ template <typename Function, typename... Args>
16869// / @see Task::Importance::Critical
16970template <typename Function, typename ... Args>
17071[[nodiscard]] auto CriticalAsyncNoSpan (Function&& f, Args&&... args) {
171- return CriticalAsyncNoSpan (
172- current_task::GetTaskProcessor (),
173- std::forward<Function>(f),
174- std::forward<Args>(args)...
175- );
176- }
177-
178- // / @overload
179- // / @see Task::Importance::Critical
180- template <typename Function, typename ... Args>
181- [[nodiscard]] auto SharedCriticalAsyncNoSpan (Function&& f, Args&&... args) {
182- return SharedCriticalAsyncNoSpan (
183- current_task::GetTaskProcessor (),
184- std::forward<Function>(f),
185- std::forward<Args>(args)...
186- );
187- }
188-
189- // / @overload
190- // / @see Task::Importance::Critical
191- template <typename Function, typename ... Args>
192- [[nodiscard]] auto CriticalAsyncNoSpan (Deadline deadline, Function&& f, Args&&... args) {
19372 return impl::MakeTaskWithResult<TaskWithResult>(
194- current_task::GetTaskProcessor (),
195- Task::Importance::kCritical ,
196- deadline,
73+ impl::TaskConfig{.importance = Task::Importance::kCritical },
19774 std::forward<Function>(f),
19875 std::forward<Args>(args)...
19976 );
0 commit comments