16#include "pw_async2/dispatcher_base.h"
17#include "pw_async2/dispatcher_native.h"
22template <
typename Pendable>
25 using OutputType = PendOutputOf<Pendable>;
27 : pendable_(pendable), output_(Pending()) {}
28 OutputType&& TakeOutput() {
return std::move(*output_); }
32 output_ = pendable_.Pend(cx);
61 void Post(
Task& task) PW_LOCKS_EXCLUDED(dispatcher_lock()) {
67 return native_.DoRunUntilStalled(*
this,
nullptr);
75 return native_.DoRunUntilStalled(*
this, &task);
82 template <
typename Pendable>
84 PW_LOCKS_EXCLUDED(dispatcher_lock()) {
88 return task.TakeOutput();
101 native_.DoRunToCompletion(*
this,
nullptr);
106 native_.DoRunToCompletion(*
this, &task);
110 template <
typename Pendable>
112 PW_LOCKS_EXCLUDED(dispatcher_lock()) {
115 native_.DoRunToCompletion(*
this, &task);
116 return task.TakeOutput();
Definition: dispatcher_base.h:52
A single-threaded cooperatively-scheduled runtime for async tasks.
Definition: dispatcher.h:42
pw::async2::backend::NativeDispatcher & native()
Returns a reference to the native backend-specific dispatcher type.
Definition: dispatcher.h:120
Poll RunUntilStalled()
Runs tasks until none are able to make immediate progress.
Definition: dispatcher.h:66
Dispatcher()=default
Constructs a new async Dispatcher.
void RunToCompletion()
Runs until all tasks complete.
Definition: dispatcher.h:100
Poll< PendOutputOf< Pendable > > RunPendableUntilStalled(Pendable &pendable)
Definition: dispatcher.h:83
void Post(Task &task)
Definition: dispatcher.h:61
void RunToCompletion(Task &task)
Runs until task completes.
Definition: dispatcher.h:105
Poll RunUntilStalled(Task &task)
Definition: dispatcher.h:74
PendOutputOf< Pendable > RunPendableToCompletion(Pendable &pendable)
Runs until pendable completes, returning the output of pendable.
Definition: dispatcher.h:111
constexpr Poll Readiness() const noexcept
Definition: poll.h:132
Definition: dispatcher_base.h:158
Definition: dispatcher_native.h:39
Definition: dispatcher.h:23
Poll DoPend(Context &cx) final
Definition: dispatcher.h:31