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

Overview

template<typename T>
class pw::async2::FutureTask< T >

Creates a task that pends a future until it completes.

FutureTask can be initialized in a few ways:

  • Move a future: FutureTask task(std::move(future))
  • Construct a future in place:FutureTask<MyFuture> task(arg1, arg2)
  • Refer to an existing future:FutureTask<MyFuture&> task(future)`
Warning
FutureTask is intended for test and occasional production use. A FutureTask does not contain logic, and relying too much on FutureTasks could push logic out of async tasks, which nullifies the benefits of pw_async2. Creating a task for each future is also less efficient than having one task work with multiple futures.
Inheritance diagram for pw::async2::FutureTask< T >:
pw::async2::Task pw::containers::future::IntrusiveList< T >::Item

Public Types

using future_type = std::remove_reference_t< T >
 The type of the future that is pended by this task.
 
using value_type = typename future_type::value_type
 The type produced by this tasks's future when it completes.
 

Public Member Functions

template<typename Arg , typename... Args>
constexpr FutureTask (Arg &&arg, Args &&... args)
 
Poll< value_typeTakePoll ()
 
FutureValue< future_type > & value () &
 
const FutureValue< future_type > & value () const &
 
FutureValue< future_type > && value () &&
 
const FutureValue< future_type > && value () const &&
 
FutureValue< future_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) override
 

Additional Inherited Members

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

Constructor & Destructor Documentation

◆ FutureTask()

template<typename T >
template<typename Arg , typename... Args>
constexpr pw::async2::FutureTask< T >::FutureTask ( Arg &&  arg,
Args &&...  args 
)
inlineexplicitconstexpr

Constructs a FutureTask. Forwards arguments to the future's constructor for FutureTasks that own their future. Reference FutureTasks take a mutable reference to their future.

Requires at least one argument. Default constructed futures are not permitted since since they cannot be pended.

Member Function Documentation

◆ DoPend()

template<typename T >
Poll pw::async2::FutureTask< T >::DoPend ( Context )
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.

◆ TakePoll()

template<typename T >
Poll< value_type > pw::async2::FutureTask< T >::TakePoll ( )
inline

Takes the Poll result from the most recent task run. This function is NOT thread safe. It cannot be called when the task may run on another thread.

◆ value() [1/4]

template<typename T >
FutureValue< future_type > & pw::async2::FutureTask< T >::value ( ) &
inline

Returns the value produced by the future.

Precondition
The task MUST have been joined first.

◆ value() [2/4]

template<typename T >
FutureValue< future_type > && pw::async2::FutureTask< T >::value ( ) &&
inline

Returns the value produced by the future.

Precondition
The task MUST have been joined first.

◆ value() [3/4]

template<typename T >
const FutureValue< future_type > & pw::async2::FutureTask< T >::value ( ) const &
inline

Returns the value produced by the future.

Precondition
The task MUST have been joined first.

◆ value() [4/4]

template<typename T >
const FutureValue< future_type > && pw::async2::FutureTask< T >::value ( ) const &&
inline

Returns the value produced by the future.

Precondition
The task MUST have been joined first.

◆ Wait()

template<typename T >
FutureValue< future_type > & pw::async2::FutureTask< T >::Wait ( )
inline

Joins that task, blocking until the future completes, then returns a reference its value.


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