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

Overview

template<typename T, typename AllocationErrorHandler = pw::Function<void()>, ReturnValuePolicy policy = std::is_void_v<T> ? ReturnValuePolicy::kDiscard : ReturnValuePolicy::kKeep>
requires std::invocable<AllocationErrorHandler>
class pw::async2::FallibleCoroTask< T, AllocationErrorHandler, policy >

A Task that delegates to a provided Coro<T> and executes an error handler function if coroutine allocation fails.

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

Public Types

using value_type = std::conditional_t< std::is_void_v< T >, ReadyType, T >
 

Public Member Functions

template<typename ErrorHandler >
 FallibleCoroTask (Coro< T > &&coro, ErrorHandler &&error_handler)
 
 FallibleCoroTask (const FallibleCoroTask &)=delete
 
FallibleCoroTaskoperator= (const FallibleCoroTask &)=delete
 
 FallibleCoroTask (FallibleCoroTask &&)=delete
 
FallibleCoroTaskoperator= (FallibleCoroTask &&)=delete
 
bool ok () const
 
bool has_value () const
 
value_type & value ()
 
const value_type & value () const
 
std::optional< value_type > & Wait ()
 
- 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

◆ FallibleCoroTask()

template<typename T , typename AllocationErrorHandler = pw::Function<void()>, ReturnValuePolicy policy = std::is_void_v<T> ? ReturnValuePolicy::kDiscard : ReturnValuePolicy::kKeep>
template<typename ErrorHandler >
pw::async2::FallibleCoroTask< T, AllocationErrorHandler, policy >::FallibleCoroTask ( Coro< T > &&  coro,
ErrorHandler &&  error_handler 
)
inline

Create a new Task that runs coro, invoking or_else if allocation fails.

Member Function Documentation

◆ DoPend()

template<typename T , typename AllocationErrorHandler = pw::Function<void()>, ReturnValuePolicy policy = std::is_void_v<T> ? ReturnValuePolicy::kDiscard : ReturnValuePolicy::kKeep>
Poll pw::async2::FallibleCoroTask< T, AllocationErrorHandler, 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 , typename AllocationErrorHandler = pw::Function<void()>, ReturnValuePolicy policy = std::is_void_v<T> ? ReturnValuePolicy::kDiscard : ReturnValuePolicy::kKeep>
bool pw::async2::FallibleCoroTask< T, AllocationErrorHandler, policy >::has_value ( ) const
inline

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

◆ ok()

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

Returns whether this FallibleCoroTask wraps a valid Coro and can be pended. Pending a !ok() FallibleCoroTask calls the error handler.

This will be false if Coro allocation failed.

◆ value() [1/2]

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

The return value from the coroutine.

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

◆ value() [2/2]

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

The return value from the coroutine.

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

◆ Wait()

template<typename T , typename AllocationErrorHandler = pw::Function<void()>, ReturnValuePolicy policy = std::is_void_v<T> ? ReturnValuePolicy::kDiscard : ReturnValuePolicy::kKeep>
std::optional< value_type > & pw::async2::FallibleCoroTask< T, AllocationErrorHandler, policy >::Wait ( )
inline

Blocks until the task completes and returns the return value in a std::optional. The std::optional is empty if coroutine allocation failed.


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