32#include "pw_async2/future.h"
33#include "pw_async2/poll.h"
34#include "pw_async2/try.h"
36namespace pw::async2::experimental {
39template <
typename Func>
44template <
typename Func>
51template <
typename Func>
56template <
typename InnerFuture,
typename Func>
60 std::invoke_result_t<Func, typename InnerFuture::value_type>;
65 inner_ = std::move(other.inner_);
68 func_.emplace(std::move(*other.func_));
73 MapFuture(InnerFuture&& inner, Func&& func)
74 : inner_(std::move(inner)), func_(std::forward<Func>(func)) {}
81 bool is_pendable()
const {
return inner_.is_pendable(); }
82 bool is_complete()
const {
return inner_.is_complete(); }
86 std::optional<Func> func_;
89template <
typename Func>
94template <
typename FirstFuture,
typename Func>
98 std::invoke_result_t<Func, typename FirstFuture::value_type>;
99 using value_type =
typename SecondFuture::value_type;
106 func_.emplace(std::move(*other.func_));
108 state_ = std::move(other.state_);
113 : func_(std::move(func)),
114 state_(std::in_place_index<0>, std::move(first)) {}
117 if (state_.index() == 0) {
118 auto& first = std::get<0>(state_);
121 state_.template emplace<1>((*func_)(result));
124 if (state_.index() == 1) {
125 auto& second = std::get<1>(state_);
127 state_.template emplace<2>();
134 bool is_pendable()
const {
return state_.index() != 2; }
135 bool is_complete()
const {
return state_.index() == 2; }
138 std::optional<Func> func_;
139 std::variant<FirstFuture, SecondFuture, std::monostate> state_;
144template <
typename InnerFuture,
146 typename = std::enable_if_t<Future<std::decay_t<InnerFuture>>>>
147auto operator|(InnerFuture&& future, MapOp<Func>&& op) {
149 std::forward<InnerFuture>(future), std::move(op.func));
152template <
typename FirstFuture,
154 typename = std::enable_if_t<Future<std::decay_t<FirstFuture>>>>
155auto operator|(FirstFuture&& future, ThenOp<Func>&& op) {
156 return ThenFuture<std::decay_t<FirstFuture>, std::decay_t<Func>>(
157 std::forward<FirstFuture>(future), std::move(op.func));
Definition: transform.h:57
Definition: transform.h:95
#define PW_TRY_READY_ASSIGN(lhs, expression)
Definition: try.h:28
constexpr PendingType Pending()
Returns a value indicating that an operation was not yet able to complete.
Definition: poll.h:353
Definition: transform.h:40
Definition: transform.h:45