21#include "pw_async2/dispatcher.h"
22#include "pw_async2/future.h"
23#include "pw_async2/poll.h"
24#include "pw_containers/optional_tuple.h"
30template <
typename... Futures>
33 static_assert(
sizeof...(Futures) > 0,
34 "Cannot select over an empty set of futures");
41 : futures_(std::move(futures)...), state_(FutureState::kPending) {}
45 PendAll(cx, kTupleIndexSequence, tuple);
47 state_.MarkComplete();
48 futures_ = std::tuple<Futures...>();
54 [[nodiscard]]
constexpr bool is_pendable()
const {
57 [[nodiscard]]
constexpr bool is_complete()
const {
62 static constexpr auto kTupleIndexSequence =
63 std::make_index_sequence<
sizeof...(Futures)>();
65 enum State : uint8_t {
73 template <
size_t... Is>
75 (PendFuture<Is>(cx, result), ...);
78 template <
size_t kTupleIndex>
80 auto& future = std::get<kTupleIndex>(futures_);
81 if (future.is_complete()) {
85 auto poll = future.Pend(cx);
87 result.template emplace<kTupleIndex>(std::move(*poll));
91 std::tuple<Futures...> futures_;
95template <
typename... Futures>
103template <
typename... Futures>
106 "All arguments to Select must be Future types");
Definition: optional_tuple.h:112
constexpr bool empty() const
Checks if the OptionalTuple contains no active elements.
Definition: optional_tuple.h:180
constexpr bool is_pendable() const
Definition: future.h:156
constexpr bool is_complete() const
Definition: future.h:162
SelectFuture< Futures... > Select(Futures &&... futures)
Definition: select.h:104
constexpr PendingType Pending()
Returns a value indicating that an operation was not yet able to complete.
Definition: poll.h:353