C/C++ API Reference
Loading...
Searching...
No Matches
pw::async2::CallbackTask< FutureType, Func > Class Template Referencefinal

Overview

template<typename FutureType, typename Func = internal::CallbackType<FutureType>>
class pw::async2::CallbackTask< FutureType, Func >

A Task which pends a future and invokes a provided callback with its output when it returns Ready.

A CallbackTask terminates after the underlying future returns Ready and can be cleaned up afterwards.

Inheritance diagram for pw::async2::CallbackTask< FutureType, Func >:
pw::async2::Task pw::containers::future::IntrusiveList< T >::Item

Public Types

using value_type = typename FutureType::value_type
 

Public Member Functions

constexpr CallbackTask (Func &&callback, FutureType &&future)
 
- 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 ()
 

Static Public Member Functions

template<typename Callback , typename... Args>
static constexpr auto Emplace (Callback &&callback, Args &&... future_args)
 

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

◆ CallbackTask()

template<typename FutureType , typename Func = internal::CallbackType<FutureType>>
constexpr pw::async2::CallbackTask< FutureType, Func >::CallbackTask ( Func &&  callback,
FutureType &&  future 
)
inlineconstexpr

Creates a new CallbackTask which will run the future to completion and then invoke the callback with the result.

Member Function Documentation

◆ DoPend()

template<typename FutureType , typename Func = internal::CallbackType<FutureType>>
Poll pw::async2::CallbackTask< FutureType, Func >::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.

◆ Emplace()

template<typename FutureType , typename Func = internal::CallbackType<FutureType>>
template<typename Callback , typename... Args>
static constexpr auto pw::async2::CallbackTask< FutureType, Func >::Emplace ( Callback &&  callback,
Args &&...  future_args 
)
inlinestaticconstexpr

Creates a new CallbackTask which will run the future to completion and then invoke the callback with the result.

This function constructs the FutureType in-place from future_args.


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