C/C++ API Reference
Loading...
Searching...
No Matches
pw::async2::CoroTask< T, policy > Class Template Referencefinal

Overview

template<typename T, ReturnValuePolicy policy = std::is_void_v<T> ? ReturnValuePolicy::kDiscard : ReturnValuePolicy::kKeep>
class pw::async2::CoroTask< T, policy >

A Task that delegates to a provided Coro<T>.

The provided Coro is polled when Pend is called on this task.

Inheritance diagram for pw::async2::CoroTask< T, policy >:
pw::async2::Task pw::containers::future::IntrusiveList< T >::Item

Public Types

using value_type = T
 

Public Member Functions

 CoroTask (Coro< T > &&coro)
 
 CoroTask (const CoroTask &)=delete
 
CoroTaskoperator= (const CoroTask &)=delete
 
 CoroTask (CoroTask &&)=delete
 
CoroTaskoperator= (CoroTask &&)=delete
 
bool ok () const
 
bool has_value () const
 
value_type & value ()
 
const value_type & value () const
 
value_type & Wait ()
 Blocks until the task completes and returns a reference its return value.
 
- Public Member Functions inherited from pw::async2::Task
constexpr Task (log::Token name=kDefaultName)
 
 Task (const Task &)=delete
 
 Task (Task &&)=delete
 
Taskoperator= (const Task &)=delete
 
Taskoperator= (Task &&)=delete
 
virtual ~Task ()
 
Poll Pend (Context &cx)
 
bool IsRegistered () const
 
void Deregister ()
 
void Join ()
 

Private Member Functions

Poll DoPend (Context &cx) final
 

Additional Inherited Members

- Protected Member Functions inherited from pw::containers::future::IntrusiveList< T >::Item
constexpr Item ()=default
 

Constructor & Destructor Documentation

◆ CoroTask()

template<typename T , ReturnValuePolicy policy = std::is_void_v<T> ? ReturnValuePolicy::kDiscard : ReturnValuePolicy::kKeep>
pw::async2::CoroTask< T, policy >::CoroTask ( Coro< T > &&  coro)
inline

Creates a task that runs the provided coroutine. If the Coro is empty or failed to allocate, this CoroTask crashes when Pend is called.

Member Function Documentation

◆ DoPend()

template<typename T , ReturnValuePolicy policy = std::is_void_v<T> ? ReturnValuePolicy::kDiscard : ReturnValuePolicy::kKeep>
Poll pw::async2::CoroTask< T, policy >::DoPend ( Context )
inlinefinalprivatevirtual

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.

◆ has_value()

template<typename T , ReturnValuePolicy policy = std::is_void_v<T> ? ReturnValuePolicy::kDiscard : ReturnValuePolicy::kKeep>
bool pw::async2::CoroTask< T, policy >::has_value ( ) const
inline

Returns whether the task ran and set that value to the function's return value.

◆ ok()

template<typename T , ReturnValuePolicy policy = std::is_void_v<T> ? ReturnValuePolicy::kDiscard : ReturnValuePolicy::kKeep>
bool pw::async2::CoroTask< T, policy >::ok ( ) const
inline

Returns whether this CoroTask wraps a valid Coro and can be pended. Pending a !ok() CoroTask will crash.

This will be false if Coro allocation failed.

◆ value() [1/2]

template<typename T , ReturnValuePolicy policy = std::is_void_v<T> ? ReturnValuePolicy::kDiscard : ReturnValuePolicy::kKeep>
value_type & pw::async2::CoroTask< T, policy >::value ( )
inline

The return value from the coroutine.

Precondition
The task must have completed. Call Join to ensure it has completed.

◆ value() [2/2]

template<typename T , ReturnValuePolicy policy = std::is_void_v<T> ? ReturnValuePolicy::kDiscard : ReturnValuePolicy::kKeep>
const value_type & pw::async2::CoroTask< T, policy >::value ( ) const
inline

The return value from the coroutine.

Precondition
The task must have completed. Call Join to ensure it has completed.

The documentation for this class was generated from the following file: