Corium 1.1.0
High-Performance Zero-Heap C++20 MPSC Application Runtime
Loading...
Searching...
No Matches
WhenAll.hpp
Go to the documentation of this file.
1
7#pragma once
8
9#include <tuple>
10#include <type_traits>
11#include <utility>
12
13#include "corium/async/Task.hpp"
14
15namespace corium::async {
16
17namespace detail {
18
19template <typename... Tasks>
20inline constexpr bool all_void_tasks_v = (std::is_void_v<typename std::decay_t<Tasks>::ValueType> && ...);
21
22template <typename... Tasks>
24{
25 co_return std::tuple<typename std::decay_t<Tasks>::ValueType...>{(co_await tasks)...};
26}
27
28template <typename... Tasks>
30{
31 ((void)(co_await tasks), ...);
32 co_return;
33}
34
35} // namespace detail
36
40template <typename... Tasks>
41auto whenAll(Tasks&&... tasks)
42{
43 if constexpr (detail::all_void_tasks_v<Tasks...>) {
44 return detail::whenAllVoidImpl(std::forward<Tasks>(tasks)...);
45 } else {
46 return detail::whenAllValueImpl(std::forward<Tasks>(tasks)...);
47 }
48}
49
50} // namespace corium::async
Lazy awaitable C++20 coroutine task with zero dynamic heap allocation.
Lightweight C++20 coroutine task with zero-heap resumption chaining and configurable frame allocator.
Definition Task.hpp:22
auto whenAll(Tasks &&... tasks)
Awaits concurrent or sequential completion of multiple Task coroutines.
Definition WhenAll.hpp:41
Task< void > whenAllVoidImpl(Tasks... tasks)
Definition WhenAll.hpp:29
Task< std::tuple< typename std::decay_t< Tasks >::ValueType... > > whenAllValueImpl(Tasks... tasks)
Definition WhenAll.hpp:23
constexpr bool all_void_tasks_v
Definition WhenAll.hpp:20
Definition AsyncEvent.hpp:14