16#include "pw_async2/dispatcher.h"
27template <
typename... Pendables>
30 static constexpr auto kTupleIndexSequence =
31 std::make_index_sequence<
sizeof...(Pendables)>();
32 using TupleOfOutputRvalues = std::tuple<PendOutputOf<Pendables>&&...>;
36 explicit Join(Pendables&&... pendables)
37 : pendables_(std::move(pendables)...),
38 outputs_(
Poll<PendOutputOf<Pendables>>(
Pending())...) {}
43 if (!PendElements(cx, kTupleIndexSequence)) {
46 return TakeOutputs(kTupleIndexSequence);
53 template <
size_t... Is>
54 bool PendElements(
Context& cx, std::index_sequence<Is...>) {
55 return (... && PendElement<Is>(cx));
59 template <
size_t... Is>
60 Poll<TupleOfOutputRvalues> TakeOutputs(std::index_sequence<Is...>) {
61 return Poll<TupleOfOutputRvalues>(
62 std::forward_as_tuple<PendOutputOf<Pendables>...>(TakeOutput<Is>()...));
70 template <
size_t kTupleIndex>
71 bool PendElement(Context& cx) {
72 auto& output = std::get<kTupleIndex>(outputs_);
73 if (output.IsReady()) {
76 output = std::get<kTupleIndex>(pendables_).Pend(cx);
77 return output.IsReady();
81 template <
size_t kTupleIndex>
82 PendOutputOf<
typename std::tuple_element<kTupleIndex,
83 std::tuple<Pendables...>>::type>&&
85 return std::move(std::get<kTupleIndex>(outputs_).value());
88 std::tuple<Pendables...> pendables_;
89 std::tuple<Poll<PendOutputOf<Pendables>>...> outputs_;
92template <
typename... Pendables>
93Join(Pendables&&...) -> Join<Pendables...>;
Join(Pendables &&... pendables)
Creates a Join from a series of pendable values.
Definition: join.h:36
Poll< TupleOfOutputRvalues > Pend(Context &cx)
Definition: join.h:42
constexpr PendingType Pending()
Returns a value indicating that an operation was not yet able to complete.
Definition: poll.h:271