C/C++ API Reference
Loading...
Searching...
No Matches
pw::async2::Task Class Referenceabstract

Overview

A task which may complete one or more asynchronous operations.

The Task interface is commonly implemented by users wishing to schedule work on an asynchronous Dispatcher. To do this, users may subclass Task, providing an implementation of the DoPend method which advances the state of the Task as far as possible before yielding back to the Dispatcher.

This process works similarly to cooperatively-scheduled green threads or coroutines, with a Task representing a single logical "thread" of execution. Unlike some green thread or coroutine implementations, Task does not imply a separately-allocated stack: Task state is most commonly stored in fields of the Task subclass.

Once defined by a user, Tasks may be run by passing them to a Dispatcher via Dispatcher::Post. The Dispatcher will then Pend the Task every time that the Task indicates it is able to make progress.

Note that Task objects must not be destroyed while they are actively being Pend'd by a Dispatcher. To protect against this, be sure to do one of the following:

Inheritance diagram for pw::async2::Task:
pw::IntrusiveQueue< T >::Item pw::async2::Context pw::async2::CallbackTask< FutureType, Func > pw::async2::CoroOrElseTask pw::async2::CoroTask< T, policy > pw::async2::CoroTask< T, ReturnValuePolicy::kDiscard > pw::async2::FallibleCoroTask< T, AllocationErrorHandler, policy > pw::async2::FallibleCoroTask< T, AllocationErrorHandler, ReturnValuePolicy::kDiscard > pw::async2::FuncTask< Func > pw::async2::FutureTask< T > pw::async2::RunOnceTask< Func, ReturnValuePolicy > pw::async2::RunOnceTask< Func, ReturnValuePolicy::kDiscard >

Public Member Functions

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 ()
 

Protected Types

using Context = ::pw::async2::Context
 

Private Member Functions

virtual Poll DoPend (Context &)=0
 

Friends

class Dispatcher
 
class Waker
 

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