Skip to main content
Pigweed's logo Pigweed
code_xml
  1. Home
  2. Reference
  3. C/C++
  4. Async & concurrency
  5. pw_async2
  6. Futures
  7. pw::async2::ValueFuture< T > Class Template Reference
Loading...
Searching...
No Matches
pw::async2::ValueFuture< T > Class Template Reference

Overview

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

A future that holds a single value.

A ValueFuture is a concrete Future implementation that is vended by a ValueProvider or a BroadcastValueProvider. It waits until the provider resolves it with a value.

Public Types

using value_type = T
 

Public Member Functions

 ValueFuture (ValueFuture &&other) noexcept
 
ValueFuture & operator= (ValueFuture &&other) noexcept
 
void Cancel ()
 
Poll< T > Pend (Context &cx)
 
bool is_pendable () const
 
bool is_complete () const
 

Static Public Member Functions

template<typename... Args>
static ValueFuture Resolved (Args &&... args)
 

Protected Member Functions

void MoveFrom (ValueFuture &other)
 
template<typename Fn >
void MoveFrom (ValueFuture &other, Fn &&move_members)
 

Friends

class ValueProvider< T >
 
class BroadcastValueProvider< T >
 
template<typename DerivedFuture >
class DerivedValueProvider
 
template<typename U , typename FutureType >
class ValueListProvider
 

Member Function Documentation

◆ Cancel()

template<typename T >
void pw::async2::ValueFuture< T >::Cancel ( )
inline

Cancels the future.

Always call Cancel() in the destructor of any class derived from ValueFuture to ensure the future is unlisted before the derived class members are destroyed.

◆ MoveFrom() [1/2]

template<typename T >
void pw::async2::ValueFuture< T >::MoveFrom ( ValueFuture< T > &  other)
inlineprotected

Moves the base ValueFuture from other while holding the provider lock.

Use this overload when moving a ValueFuture or a derived future that has no additional state accessed by the provider. If the derived class has member variables that may be inspected by the provider (e.g., via ResolveIf or ResolveFirstMatching), use MoveFrom(other, move_members) instead so that those members are moved atomically under the same lock acquisition.

◆ MoveFrom() [2/2]

template<typename T >
template<typename Fn >
void pw::async2::ValueFuture< T >::MoveFrom ( ValueFuture< T > &  other,
Fn &&  move_members 
)
inlineprotected

Moves the base ValueFuture from other and invokes move_members while holding the provider lock.

Always call MoveFrom in the move constructor and move assignment operator of any class derived from ValueFuture to ensure derived class members are initialized before a concurrent provider operation can access the moved-to future.

◆ Resolved()

template<typename T >
template<typename... Args>
static ValueFuture pw::async2::ValueFuture< T >::Resolved ( Args &&...  args)
inlinestatic

Creates a ValueFuture that is already resolved by constructing its value in-place.


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