10#include <userver/engine/async.hpp>
11#include <userver/utils/fast_pimpl.hpp>
12#include <userver/utils/lazy_prvalue.hpp>
14USERVER_NAMESPACE_BEGIN
23 enum class InheritVariables { kYes, kNo };
25 explicit SpanWrapCall(std::string&& name, InheritVariables inherit_variables);
27 SpanWrapCall(
const SpanWrapCall&) =
delete;
28 SpanWrapCall(SpanWrapCall&&) =
delete;
29 SpanWrapCall& operator=(
const SpanWrapCall&) =
delete;
30 SpanWrapCall& operator=(SpanWrapCall&&) =
delete;
33 template <
typename Function,
typename... Args>
34 auto operator()(Function&& f, Args&&... args) {
36 return std::invoke(std::forward<Function>(f), std::forward<Args>(args)...);
40 void DoBeforeInvoke();
44 static constexpr std::size_t kImplSize = 4264;
45 static constexpr std::size_t kImplAlign = 8;
46 utils::FastPimpl<Impl, kImplSize, kImplAlign> pimpl_;
50inline auto SpanLazyPrvalue(std::string&& name) {
51 return utils::LazyPrvalue([&name] {
52 return SpanWrapCall(std::move(name), SpanWrapCall::InheritVariables::kYes);
74template <
typename Function,
typename... Args>
76 std::string name, Function&& f,
78 return engine::CriticalAsyncNoSpan(
79 task_processor, impl::SpanLazyPrvalue(std::move(name)),
80 std::forward<Function>(f), std::forward<Args>(args)...);
100template <
typename Function,
typename... Args>
102 std::string name, Function&& f,
104 return engine::SharedCriticalAsyncNoSpan(
105 task_processor, impl::SpanLazyPrvalue(std::move(name)),
106 std::forward<Function>(f), std::forward<Args>(args)...);
126template <
typename Function,
typename... Args>
127[[nodiscard]]
auto Async(engine::TaskProcessor& task_processor,
128 std::string name, Function&& f, Args&&... args) {
129 return engine::AsyncNoSpan(
130 task_processor, impl::SpanLazyPrvalue(std::move(name)),
131 std::forward<Function>(f), std::forward<Args>(args)...);
152template <
typename Function,
typename... Args>
153[[nodiscard]]
auto SharedAsync(engine::TaskProcessor& task_processor,
154 std::string name, Function&& f, Args&&... args) {
155 return engine::SharedAsyncNoSpan(
156 task_processor, impl::SpanLazyPrvalue(std::move(name)),
157 std::forward<Function>(f), std::forward<Args>(args)...);
174template <
typename Function,
typename... Args>
175[[nodiscard]]
auto Async(engine::TaskProcessor& task_processor,
176 std::string name, engine::Deadline deadline,
177 Function&& f, Args&&... args) {
178 return engine::AsyncNoSpan(
179 task_processor, deadline, impl::SpanLazyPrvalue(std::move(name)),
180 std::forward<Function>(f), std::forward<Args>(args)...);
198template <
typename Function,
typename... Args>
199[[nodiscard]]
auto SharedAsync(engine::TaskProcessor& task_processor,
200 std::string name, engine::Deadline deadline,
201 Function&& f, Args&&... args) {
202 return engine::SharedAsyncNoSpan(
203 task_processor, deadline, impl::SpanLazyPrvalue(std::move(name)),
204 std::forward<Function>(f), std::forward<Args>(args)...);
223template <
typename Function,
typename... Args>
227 std::move(name), std::forward<Function>(f),
228 std::forward<Args>(args)...);
248template <
typename Function,
typename... Args>
252 std::move(name), std::forward<Function>(f),
253 std::forward<Args>(args)...);
273template <
typename Function,
typename... Args>
274[[nodiscard]]
auto Async(std::string name, Function&& f, Args&&... args) {
276 std::forward<Function>(f), std::forward<Args>(args)...);
297template <
typename Function,
typename... Args>
298[[nodiscard]]
auto SharedAsync(std::string name, Function&& f, Args&&... args) {
300 std::move(name), std::forward<Function>(f),
301 std::forward<Args>(args)...);
318template <
typename Function,
typename... Args>
319[[nodiscard]]
auto Async(std::string name, engine::Deadline deadline,
320 Function&& f, Args&&... args) {
322 deadline, std::forward<Function>(f),
323 std::forward<Args>(args)...);
341template <
typename Function,
typename... Args>
342[[nodiscard]]
auto SharedAsync(std::string name, engine::Deadline deadline,
343 Function&& f, Args&&... args) {
344 return utils::SharedAsync(
346 std::forward<Function>(f), std::forward<Args>(args)...);
379template <
typename Function,
typename... Args>
381 engine::TaskProcessor& task_processor,
382 Function&& f, Args&&... args) {
383 return engine::AsyncNoSpan(
384 task_processor,
utils::LazyPrvalue([&] {
385 return impl::SpanWrapCall(std::move(name),
386 impl::SpanWrapCall::InheritVariables::kNo);
388 std::forward<Function>(f), std::forward<Args>(args)...);