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);
221template <
typename Function,
typename... Args>
222[[nodiscard]]
auto Async(std::string name, Function&& f, Args&&... args) {
223 return engine::AsyncNoSpan(engine::current_task::GetTaskProcessor(),
224 impl::SpanLazyPrvalue(std::move(name)),
225 std::forward<Function>(f),
226 std::forward<Args>(args)...);
240template <
typename Function,
typename... Args>
241[[nodiscard]]
auto Async(engine::TaskProcessor& task_processor,
242 std::string name, Function&& f, Args&&... args) {
243 return engine::AsyncNoSpan(
244 task_processor, impl::SpanLazyPrvalue(std::move(name)),
245 std::forward<Function>(f), std::forward<Args>(args)...);
259template <
typename Function,
typename... Args>
261 std::string name, Function&& f,
263 return engine::CriticalAsyncNoSpan(
264 task_processor, impl::SpanLazyPrvalue(std::move(name)),
265 std::forward<Function>(f), std::forward<Args>(args)...);
279template <
typename Function,
typename... Args>
281 std::string name, Function&& f,
283 return engine::SharedCriticalAsyncNoSpan(
284 task_processor, impl::SpanLazyPrvalue(std::move(name)),
285 std::forward<Function>(f), std::forward<Args>(args)...);
299template <
typename Function,
typename... Args>
300[[nodiscard]]
auto SharedAsync(engine::TaskProcessor& task_processor,
301 std::string name, Function&& f, Args&&... args) {
302 return engine::SharedAsyncNoSpan(
303 task_processor, impl::SpanLazyPrvalue(std::move(name)),
304 std::forward<Function>(f), std::forward<Args>(args)...);
318template <
typename Function,
typename... Args>
319[[nodiscard]]
auto Async(engine::TaskProcessor& task_processor,
320 std::string name, engine::Deadline deadline,
321 Function&& f, Args&&... args) {
322 return engine::AsyncNoSpan(
323 task_processor, deadline, impl::SpanLazyPrvalue(std::move(name)),
324 std::forward<Function>(f), std::forward<Args>(args)...);
338template <
typename Function,
typename... Args>
339[[nodiscard]]
auto SharedAsync(engine::TaskProcessor& task_processor,
340 std::string name, engine::Deadline deadline,
341 Function&& f, Args&&... args) {
342 return engine::SharedAsyncNoSpan(
343 task_processor, deadline, impl::SpanLazyPrvalue(std::move(name)),
344 std::forward<Function>(f), std::forward<Args>(args)...);
357template <
typename Function,
typename... Args>
361 std::move(name), std::forward<Function>(f),
362 std::forward<Args>(args)...);
375template <
typename Function,
typename... Args>
379 std::move(name), std::forward<Function>(f),
380 std::forward<Args>(args)...);
393template <
typename Function,
typename... Args>
394[[nodiscard]]
auto SharedAsync(std::string name, Function&& f, Args&&... args) {
396 std::move(name), std::forward<Function>(f),
397 std::forward<Args>(args)...);
410template <
typename Function,
typename... Args>
411[[nodiscard]]
auto Async(std::string name, engine::Deadline deadline,
412 Function&& f, Args&&... args) {
414 deadline, std::forward<Function>(f),
415 std::forward<Args>(args)...);
428template <
typename Function,
typename... Args>
429[[nodiscard]]
auto SharedAsync(std::string name, engine::Deadline deadline,
430 Function&& f, Args&&... args) {
431 return utils::SharedAsync(
433 std::forward<Function>(f), std::forward<Args>(args)...);
466template <
typename Function,
typename... Args>
468 engine::TaskProcessor& task_processor,
469 Function&& f, Args&&... args) {
470 return engine::AsyncNoSpan(
471 task_processor, utils::LazyPrvalue([&] {
472 return impl::SpanWrapCall(std::move(name),
473 impl::SpanWrapCall::InheritVariables::kNo);
475 std::forward<Function>(f), std::forward<Args>(args)...);
491template <
typename Function,
typename... Args>
493 std::string name, engine::TaskProcessor& task_processor, Function&& f,
495 return engine::CriticalAsyncNoSpan(
496 task_processor, utils::LazyPrvalue([&] {
497 return impl::SpanWrapCall(std::move(name),
498 impl::SpanWrapCall::InheritVariables::kNo);
500 std::forward<Function>(f), std::forward<Args>(args)...);