18#include "pw_async2/coro.h"
19#include "pw_async2/func_task.h"
20#include "pw_async2/task.h"
31 ? ReturnValuePolicy::kDiscard
32 : ReturnValuePolicy::kKeep>
41 coro_(std::move(coro)),
42 return_value_(internal::CoroPollState::kPending) {}
55 [[nodiscard]]
bool ok()
const {
return coro_.ok(); }
59 bool has_value()
const {
return return_value_.has_value(); }
64 value_type&
value() {
return return_value_.value(); }
67 const value_type&
value()
const {
return return_value_.value(); }
72 return *return_value_;
78 return_value_ = coro_.Pend(cx);
79 switch (return_value_.state()) {
80 case internal::CoroPollState::kPending:
82 case internal::CoroPollState::kAborted:
83 internal::CrashDueToCoroutineAllocationFailure();
84 case internal::CoroPollState::kReady:
115 [[nodiscard]]
bool ok()
const {
return coro_.ok(); }
120 switch (coro_.Pend(cx).state()) {
121 case internal::CoroPollState::kPending:
123 case internal::CoroPollState::kAborted:
124 internal::CrashDueToCoroutineAllocationFailure();
125 case internal::CoroPollState::kReady:
134CoroTask(Coro<T>&&) -> CoroTask<T>;
Poll DoPend(Context &cx) final
Definition: coro_task.h:118
CoroTask(Coro< T > &&coro)
Definition: coro_task.h:101
bool ok() const
Definition: coro_task.h:115
Definition: coro_task.h:33
value_type & value()
Definition: coro_task.h:64
const value_type & value() const
Definition: coro_task.h:67
bool ok() const
Definition: coro_task.h:55
value_type & Wait()
Blocks until the task completes and returns a reference its return value.
Definition: coro_task.h:70
bool has_value() const
Definition: coro_task.h:59
CoroTask(Coro< T > &&coro)
Definition: coro_task.h:39
Poll DoPend(Context &cx) final
Definition: coro_task.h:76
Definition: optional.h:65
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