Skip to content

Commit 7157ffc

Browse files
committed
executor
1 parent 63198bb commit 7157ffc

1 file changed

Lines changed: 15 additions & 24 deletions

File tree

include/pot/executors/executor.h

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,14 @@ class executor
5454

5555
private:
5656
template <bool Lazy, typename Func, typename... Args>
57-
auto do_run(Func &&func, Args &&...args) -> std::conditional_t<
57+
58+
auto do_run(Func func, Args... args) -> std::conditional_t<
5859
Lazy,
5960
pot::coroutines::lazy_task<
6061
pot::traits::awaitable_value_t<std::invoke_result_t<Func, Args...>>>,
6162
pot::coroutines::task<pot::traits::awaitable_value_t<std::invoke_result_t<Func, Args...>>>>
6263
{
6364
using Ret = std::invoke_result_t<Func, Args...>;
64-
using Val = pot::traits::awaitable_value_t<Ret>;
65-
66-
using ReturnTaskType =
67-
std::conditional_t<Lazy, pot::coroutines::lazy_task<Val>, pot::coroutines::task<Val>>;
6865

6966
struct schedule_awaiter
7067
{
@@ -79,30 +76,24 @@ class executor
7976
void await_resume() const noexcept {}
8077
};
8178

82-
auto co_wrapper = [](executor *exec, auto fn, auto args_tuple) mutable -> ReturnTaskType
79+
co_await schedule_awaiter{this};
80+
81+
if constexpr (std::is_void_v<Ret>)
8382
{
84-
co_await schedule_awaiter{exec};
85-
86-
if constexpr (std::is_void_v<Ret>)
83+
std::invoke(std::move(func), std::move(args)...);
84+
co_return;
85+
}
86+
else
87+
{
88+
if constexpr (pot::traits::is_task_v<Ret> || pot::traits::is_lazy_task_v<Ret>)
8789
{
88-
std::apply(std::move(fn), std::move(args_tuple));
89-
co_return;
90+
co_return co_await std::invoke(std::move(func), std::move(args)...);
9091
}
9192
else
9293
{
93-
if constexpr (pot::traits::is_task_v<Ret> || pot::traits::is_lazy_task_v<Ret>)
94-
{
95-
co_return co_await std::apply(std::move(fn), std::move(args_tuple));
96-
}
97-
else
98-
{
99-
co_return std::apply(std::move(fn), std::move(args_tuple));
100-
}
94+
co_return std::invoke(std::move(func), std::move(args)...);
10195
}
102-
};
103-
104-
return co_wrapper(this, std::decay_t<Func>(std::forward<Func>(func)),
105-
std::make_tuple(std::decay_t<Args>(std::forward<Args>(args))...));
96+
}
10697
}
10798
};
108-
} // namespace pot
99+
}

0 commit comments

Comments
 (0)