template<typename Func = Function<Poll<>()>,
ReturnValuePolicy = std::is_void_v<std::invoke_result_t<Func>> ? ReturnValuePolicy::kDiscard : ReturnValuePolicy::kKeep>
class pw::async2::RunOnceTask< Func, ReturnValuePolicy >
Runs a function once in a task. The task calls the function then returns Ready. The task may be posted again after it is joined.
The function's return value is stored and can be accessed through the value member after joining, or by calling Wait. A void-returning function use a different RunOnceTask specialization that does not provide the return value. To discard the return value for non-void functions, use the ReturnValuePolicy::kDiscard template argument.
- Warning
RunOnceTask should be used rarely, such as in tests, truly one-off cases, or as a last resort for sync-async interop. pw_async2 should not be used as a work queue. Overuse of RunOnceTask forfeits the benefits of pw_async2, scattering logic across a mess of callbacks instead of organizing it linearly in a task.
template<typename Func = Function<Poll<>()>,
ReturnValuePolicy = std::is_void_v<std::invoke_result_t<Func>> ? ReturnValuePolicy::kDiscard : ReturnValuePolicy::kKeep>
|
|
inlineoverrideprivatevirtual |
Attempts to advance this Task to completion.
This method should not perform synchronous waiting, as doing so may block the main Dispatcher loop and prevent other Task s from progressing. Because of this, Task s should not invoke blocking Dispatcher methods such as RunUntilComplete.
Tasks should also avoid invoking RunUntilStalled on their own Dispatcher.
Returns Ready if complete, or Pending if the Task was not yet able to complete.
If Pending is returned, the Task must ensure it is woken up when it is able to make progress. To do this, Task::Pend must arrange for Waker::Wake to be called, either by storing a copy of the Waker away to be awoken by another system (such as an interrupt handler).
Implements pw::async2::Task.