tmc::spawn_tuple()#
spawn_tuple()
wraps multiple awaitables into a single awaitable, that completes when all of the wrapped awaitables complete.
Each element of the awaitable parameter pack (or tuple parameter) will return its value to the the corresponding element in the result tuple.
If the result type of a particular awaitable parameter would be void
, its element in the result tuple will be a std::monostate
instead.
If the result type of a particular awaitable parameter is not default-constructible, its element in the result tuple will be a std::optional<Result>
.
Awaitable Customizations#
The resulting awaitable supports these Awaitable Customizations:
run_on()
,
resume_on()
,
with_priority()
,
co_await
,
fork()
,
detach()
.
Additionally, it supports a special awaitable customization (execution mode):
.result_each()
#
Rather than waiting for all results at once, each result will be made
available immediately as it becomes ready. Each time this is co_awaited, it will return
the index of a single ready result. The result indexes correspond to the
indexes of the originally submitted tasks in the input argument list or tuple, and the values can be
accessed using .get<index>()
.
Results may become ready in any order, but
when awaited repeatedly, each index from [0..task_count) will be
returned exactly once. You must await this repeatedly until all tasks
are complete, at which point the index returned will be equal to the
value of end().
API Reference#
-
template<typename ...Awaitable>
aw_spawn_tuple<tmc::detail::forward_awaitable<Awaitable>...> tmc::spawn_tuple(Awaitable&&... Tasks)# Spawns multiple awaitables and returns an awaiter that allows you to await all of the results. These awaitables may have different return types, and the results will be returned in a tuple. If void-returning awaitable is submitted, its result type will be replaced with std::monostate in the tuple.
Does not support non-awaitable types (such as regular functors).
-
template<typename ...Awaitable>
aw_spawn_tuple<Awaitable...> tmc::spawn_tuple(std::tuple<Awaitable...> &&Tasks)# Spawns multiple awaitables and returns an awaiter that allows you to await all of the results. These awaitables may have different return types, and the results will be returned in a tuple. If a void-returning awaitable is submitted, its result type will be replaced with std::monostate in the tuple.
Does not support non-awaitable types (such as regular functors).