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

Overview

FutureCore provides common functionality for futures that need to be wakeable and stored in a list.

This class provides the core mechanism for:

  • Storing a Waker to be woken up.
  • Tracking future state.
  • Being part of an IntrusiveList.

It is designed to be used as a member of a concrete future class (composition) rather than a base class, to simplify move semantics and object lifetime.

Inheritance diagram for pw::async2::FutureCore:
pw::IntrusiveForwardList< T >::Item

Public Types

enum  ReadyForCompletion { kReadyForCompletion }
 
enum  Pending { kPending }
 Tag type to construct an active FutureCore. Pend may be called.
 

Public Member Functions

 FutureCore (FutureCore &&other) noexcept
 
FutureCoreoperator= (FutureCore &&other) noexcept
 
constexpr FutureCore (Pending)
 
constexpr FutureCore (ReadyForCompletion)
 
 FutureCore (const FutureCore &)=delete
 
FutureCoreoperator= (const FutureCore &)=delete
 
bool is_pendable () const
 
bool is_complete () const
 
bool is_ready () const
 
void Wake ()
 
void WakeAndMarkReady ()
 
void Unlist ()
 Removes this future from its list, if it is in one.
 
template<typename FutureType >
auto DoPend (FutureType &future, Context &cx)
 
bool in_list () const
 

Friends

class BaseFutureList
 

Additional Inherited Members

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

Member Enumeration Documentation

◆ ReadyForCompletion

Tag type to construct a FutureCore for which the next call to Pend will return Ready.

Constructor & Destructor Documentation

◆ FutureCore() [1/2]

constexpr pw::async2::FutureCore::FutureCore ( Pending  )
inlineexplicitconstexpr

Constructs a pending FutureCore that represents an async operation. Pend must be called until it returns Ready.

A pending FutureCore must be tracked by its provider (e.g. in a FutureList).

◆ FutureCore() [2/2]

constexpr pw::async2::FutureCore::FutureCore ( ReadyForCompletion  )
inlineexplicitconstexpr

Creates a wakeable future that is ready for completion. The next call to Pend must return Ready.

Member Function Documentation

◆ in_list()

bool pw::async2::FutureCore::in_list ( ) const
inline
Returns
whether the future is currently in a list.

◆ is_complete()

bool pw::async2::FutureCore::is_complete ( ) const
inline
Returns
Whether the future has completed: the future's Pend() returned Ready.

◆ is_pendable()

bool pw::async2::FutureCore::is_pendable ( ) const
inline
Returns
Whether the future's Pend() function can be called.

◆ is_ready()

bool pw::async2::FutureCore::is_ready ( ) const
inline
Returns
true if the next Pend() call is guaranteed to return Ready. Depending on the implementation, Pend() may return Ready while is_ready is false. Future implementations call WakeAndMarkReady to set is_ready to true.

◆ Wake()

void pw::async2::FutureCore::Wake ( )
inline

Wakes the task waiting on the future, if any. The future must be pended in order to make progress.

◆ WakeAndMarkReady()

void pw::async2::FutureCore::WakeAndMarkReady ( )
inline

Wakes the task pending the future and sets is_ready to true. Only call this if the next call to to the future's Pend() will return Ready.


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