18#include "pw_async2/coro.h"
19#include "pw_async2/func_task.h"
20#include "pw_function/function.h"
31 ? ReturnValuePolicy::kDiscard
32 : ReturnValuePolicy::kKeep>
33 requires std::invocable<AllocationErrorHandler>
36 using value_type = std::conditional_t<std::is_void_v<T>,
ReadyType, T>;
40 template <
typename ErrorHandler>
43 coro_(std::move(coro)),
44 error_handler_(std::forward<ErrorHandler>(error_handler)) {}
57 [[nodiscard]]
bool ok()
const {
return coro_.ok(); }
61 bool has_value()
const {
return return_value_.has_value(); }
66 value_type&
value() {
return return_value_.value(); }
69 const value_type&
value()
const {
return return_value_.value(); }
74 std::optional<value_type>&
Wait() {
86 auto result = coro_.Pend(cx);
87 switch (result.state()) {
88 case internal::CoroPollState::kPending:
90 case internal::CoroPollState::kAborted:
93 case internal::CoroPollState::kReady:
94 return_value_ = std::move(*result);
100 AllocationErrorHandler error_handler_;
101 std::optional<T> return_value_;
106template <
typename T,
typename AllocationErrorHandler>
108 final :
public Task {
112 coro_(std::move(coro)),
113 error_handler_(std::move(error_handler)) {}
126 [[nodiscard]]
bool ok()
const {
return coro_.ok(); }
134 switch (coro_.Pend(cx).state()) {
135 case internal::CoroPollState::kPending:
137 case internal::CoroPollState::kAborted:
140 case internal::CoroPollState::kReady:
146 AllocationErrorHandler error_handler_;
149template <
typename T,
typename AllocationErrorHandler>
150FallibleCoroTask(Coro<T>&&, AllocationErrorHandler&&)
151 -> FallibleCoroTask<T, std::decay_t<AllocationErrorHandler>>;
bool ok() const
Definition: fallible_coro_task.h:126
Poll DoPend(Context &cx) final
Definition: fallible_coro_task.h:129
Definition: fallible_coro_task.h:34
std::optional< value_type > & Wait()
Definition: fallible_coro_task.h:74
Poll DoPend(Context &cx) final
Definition: fallible_coro_task.h:80
const value_type & value() const
Definition: fallible_coro_task.h:69
FallibleCoroTask(Coro< T > &&coro, ErrorHandler &&error_handler)
Definition: fallible_coro_task.h:41
bool ok() const
Definition: fallible_coro_task.h:57
bool has_value() const
Definition: fallible_coro_task.h:61
value_type & value()
Definition: fallible_coro_task.h:66
constexpr PendingType Pending()
Returns a value indicating that an operation was not yet able to complete.
Definition: poll.h:353
constexpr Poll Ready()
Returns a value indicating completion.
Definition: poll.h:337
ReturnValuePolicy
Whether to store or discard the function's return value in RunOnceTask.
Definition: func_task.h:62
#define PW_ASYNC_TASK_NAME(name)
Generates a token for use as a task name.
Definition: task.h:32
fit::function_impl< function_internal::config::kInlineCallableSize, !function_internal::config::kEnableDynamicAllocation, FunctionType, PW_FUNCTION_DEFAULT_ALLOCATOR_TYPE > Function
Definition: function.h:73