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] {
return SpanWrapCall(std::move(name), SpanWrapCall::InheritVariables::kYes); });
219template <
typename Function,
typename... Args>
220[[nodiscard]]
auto Async(std::string name, Function&& f, Args&&... args) {
221 return engine::AsyncNoSpan(
222 engine::current_task::GetTaskProcessor(),
223 impl::SpanLazyPrvalue(std::move(name)),
224 std::forward<Function>(f),
225 std::forward<Args>(args)...
240template <
typename Function,
typename... Args>
241[[nodiscard]]
auto Async(engine::TaskProcessor& task_processor, std::string name, Function&& f, Args&&... args) {
242 return engine::AsyncNoSpan(
243 task_processor, impl::SpanLazyPrvalue(std::move(name)), std::forward<Function>(f), std::forward<Args>(args)...
258template <
typename Function,
typename... Args>
260CriticalAsync(engine::TaskProcessor& task_processor, std::string name, Function&& f, Args&&... args) {
261 return engine::CriticalAsyncNoSpan(
262 task_processor, impl::SpanLazyPrvalue(std::move(name)), std::forward<Function>(f), std::forward<Args>(args)...
277template <
typename Function,
typename... Args>
279SharedCriticalAsync(engine::TaskProcessor& task_processor, std::string name, Function&& f, Args&&... args) {
280 return engine::SharedCriticalAsyncNoSpan(
281 task_processor, impl::SpanLazyPrvalue(std::move(name)), std::forward<Function>(f), std::forward<Args>(args)...
296template <
typename Function,
typename... Args>
297[[nodiscard]]
auto SharedAsync(engine::TaskProcessor& task_processor, std::string name, Function&& f, Args&&... args) {
298 return engine::SharedAsyncNoSpan(
299 task_processor, impl::SpanLazyPrvalue(std::move(name)), std::forward<Function>(f), std::forward<Args>(args)...
314template <
typename Function,
typename... Args>
316 engine::TaskProcessor& task_processor,
318 engine::Deadline deadline,
322 return engine::AsyncNoSpan(
325 impl::SpanLazyPrvalue(std::move(name)),
326 std::forward<Function>(f),
327 std::forward<Args>(args)...
342template <
typename Function,
typename... Args>
344 engine::TaskProcessor& task_processor,
346 engine::Deadline deadline,
350 return engine::SharedAsyncNoSpan(
353 impl::SpanLazyPrvalue(std::move(name)),
354 std::forward<Function>(f),
355 std::forward<Args>(args)...
369template <
typename Function,
typename... Args>
370[[nodiscard]]
auto CriticalAsync(std::string name, Function&& f, Args&&... args) {
371 return utils::CriticalAsync(
374 std::forward<Function>(f),
375 std::forward<Args>(args)...
389template <
typename Function,
typename... Args>
391 return utils::SharedCriticalAsync(
394 std::forward<Function>(f),
395 std::forward<Args>(args)...
409template <
typename Function,
typename... Args>
410[[nodiscard]]
auto SharedAsync(std::string name, Function&& f, Args&&... args) {
411 return utils::SharedAsync(
414 std::forward<Function>(f),
415 std::forward<Args>(args)...
429template <
typename Function,
typename... Args>
430[[nodiscard]]
auto Async(std::string name, engine::Deadline deadline, Function&& f, Args&&... args) {
435 std::forward<Function>(f),
436 std::forward<Args>(args)...
450template <
typename Function,
typename... Args>
451[[nodiscard]]
auto SharedAsync(std::string name, engine::Deadline deadline, Function&& f, Args&&... args) {
452 return utils::SharedAsync(
456 std::forward<Function>(f),
457 std::forward<Args>(args)...
491template <
typename Function,
typename... Args>
493AsyncBackground(std::string name, engine::TaskProcessor& task_processor, Function&& f, Args&&... args) {
494 return engine::AsyncNoSpan(
496 utils::LazyPrvalue([&] {
497 return impl::SpanWrapCall(std::move(name), impl::SpanWrapCall::InheritVariables::kNo);
499 std::forward<Function>(f),
500 std::forward<Args>(args)...
517template <
typename Function,
typename... Args>
520 return engine::CriticalAsyncNoSpan(
522 utils::LazyPrvalue([&] {
523 return impl::SpanWrapCall(std::move(name), impl::SpanWrapCall::InheritVariables::kNo);
525 std::forward<Function>(f),
526 std::forward<Args>(args)...