|
15 | 15 | #include "runtime-light/coroutine/concepts.h" |
16 | 16 | #include "runtime-light/coroutine/type-traits.h" |
17 | 17 | #include "runtime-light/coroutine/void-value.h" |
| 18 | +#include "runtime-light/metaprogramming/type-functions.h" |
18 | 19 | #include "runtime-light/stdlib/diagnostics/logs.h" |
19 | 20 |
|
20 | 21 | namespace kphp::coro::detail::when_any { |
@@ -120,7 +121,10 @@ class when_any_ready_awaitable<std::tuple<task_types...>> { |
120 | 121 |
|
121 | 122 | const auto task_result_processor{[&result = m_awaitable.m_result](auto&& task) noexcept { |
122 | 123 | if (auto task_result{std::forward<decltype(task)>(task).result()}; !result.has_value() && task_result.has_value()) { |
123 | | - result = std::move(task_result); |
| 124 | + using result_variant_type = std::remove_cvref<decltype(result)>::type::value_type; |
| 125 | + using task_result_type = decltype(task_result)::value_type; |
| 126 | + result = |
| 127 | + result_variant_type{std::in_place_index<kphp::type_functions::variant_index<result_variant_type, task_result_type>()>, *std::move(task_result)}; |
124 | 128 | } |
125 | 129 | }}; |
126 | 130 | std::apply([&task_result_processor](auto&&... tasks) noexcept { (std::invoke(task_result_processor, std::forward<decltype(tasks)>(tasks)), ...); }, |
@@ -290,8 +294,11 @@ class when_any_task { |
290 | 294 |
|
291 | 295 | template<kphp::coro::concepts::awaitable awaitable_type> |
292 | 296 | auto make_when_any_task(awaitable_type awaitable) noexcept -> when_any_task<typename kphp::coro::awaitable_traits<awaitable_type>::awaiter_return_type> { |
293 | | - co_yield co_await std::move(awaitable); |
294 | | - co_return; |
| 297 | + if constexpr (std::is_void_v<typename kphp::coro::awaitable_traits<awaitable_type>::awaiter_return_type>) { |
| 298 | + co_await std::move(awaitable); |
| 299 | + } else { |
| 300 | + co_yield co_await std::move(awaitable); |
| 301 | + } |
295 | 302 | } |
296 | 303 |
|
297 | 304 | } // namespace kphp::coro::detail::when_any |
0 commit comments