C/C++ API Reference
Loading...
Searching...
No Matches
Futures

Overview

Values that may not be ready yet.

Learn more: Futures

Concepts

concept  pw::async2::Future
 

Classes

class  pw::async2::FutureState
 
class  pw::async2::FutureCore
 
class  pw::async2::BaseFutureList
 
class  pw::async2::CustomFutureList< kGetFutureImpl, kGetFutureCore >
 
class  pw::async2::FutureOrValue< FutureType, Enable >
 A wrapper that holds either a pending future or its resolved value. More...
 
class  pw::async2::FutureOrValue< FutureType, std::enable_if_t<!std::is_same_v< FutureValue< FutureType >, ReadyType > > >
 
class  pw::async2::FutureOrValue< FutureType, std::enable_if_t< std::is_same_v< FutureValue< FutureType >, ReadyType > > >
 
class  pw::async2::Notification
 A notification that multiple futures can wait on. More...
 
class  pw::async2::ValueFuture< T >
 
class  pw::async2::ValueFuture< void >
 
class  pw::async2::BroadcastValueProvider< T >
 
class  pw::async2::ValueProvider< T >
 
class  pw::async2::DerivedValueProvider< DerivedFuture >
 
class  pw::async2::OptionalValueProvider< T >
 
class  pw::async2::OptionalBroadcastValueProvider< T >
 
class  pw::async2::ValueListProvider< T, FutureType >
 

Macros

#define PW_FOV_TRY_ADVANCE(cx, ...)
 Macro to poll multiple FutureOrValue objects.
 

Typedefs

template<typename T >
using pw::async2::FutureValue = std::conditional_t< std::is_void_v< typename T::value_type >, ReadyType, typename T::value_type >
 
template<auto kMemberPtr>
using pw::async2::FutureList = CustomFutureList< ContainerOf< kMemberPtr, FutureCore >, MemberOf< kMemberPtr > >
 
using pw::async2::FutureOrValue< FutureType, std::enable_if_t<!std::is_same_v< FutureValue< FutureType >, ReadyType > > >::value_type = typename FutureType::value_type
 
using pw::async2::FutureOrValue< FutureType, std::enable_if_t< std::is_same_v< FutureValue< FutureType >, ReadyType > > >::value_type = void
 
using pw::async2::VoidFuture = ValueFuture< void >
 A ValueFuture that does not return any value, just a completion signal.
 
template<typename T >
using pw::async2::OptionalValueFuture = ValueFuture< std::optional< T > >
 A ValueFuture that wraps a std::optional.
 

Functions

 pw::async2::FutureOrValue< FutureType, std::enable_if_t<!std::is_same_v< FutureValue< FutureType >, ReadyType > > >::FutureOrValue (FutureType &&future)
 
 pw::async2::FutureOrValue< FutureType, std::enable_if_t<!std::is_same_v< FutureValue< FutureType >, ReadyType > > >::FutureOrValue (const FutureOrValue &)=delete
 
FutureOrValuepw::async2::FutureOrValue< FutureType, std::enable_if_t<!std::is_same_v< FutureValue< FutureType >, ReadyType > > >::operator= (const FutureOrValue &)=delete
 
 pw::async2::FutureOrValue< FutureType, std::enable_if_t<!std::is_same_v< FutureValue< FutureType >, ReadyType > > >::FutureOrValue (FutureOrValue &&)=default
 
FutureOrValuepw::async2::FutureOrValue< FutureType, std::enable_if_t<!std::is_same_v< FutureValue< FutureType >, ReadyType > > >::operator= (FutureOrValue &&)=default
 
FutureOrValuepw::async2::FutureOrValue< FutureType, std::enable_if_t<!std::is_same_v< FutureValue< FutureType >, ReadyType > > >::operator= (FutureType &&future)
 
bool pw::async2::FutureOrValue< FutureType, std::enable_if_t<!std::is_same_v< FutureValue< FutureType >, ReadyType > > >::Advance (Context &cx)
 
bool pw::async2::FutureOrValue< FutureType, std::enable_if_t<!std::is_same_v< FutureValue< FutureType >, ReadyType > > >::empty () const
 Returns true if neither a future nor its result is held.
 
bool pw::async2::FutureOrValue< FutureType, std::enable_if_t<!std::is_same_v< FutureValue< FutureType >, ReadyType > > >::has_value () const
 Returns whether the value is available.
 
bool pw::async2::FutureOrValue< FutureType, std::enable_if_t<!std::is_same_v< FutureValue< FutureType >, ReadyType > > >::has_future () const
 Returns whether an active future is stored and pending.
 
value_type & pw::async2::FutureOrValue< FutureType, std::enable_if_t<!std::is_same_v< FutureValue< FutureType >, ReadyType > > >::value () &
 Accesses the stored value. Must only be called if has_value() is true.
 
const value_type & pw::async2::FutureOrValue< FutureType, std::enable_if_t<!std::is_same_v< FutureValue< FutureType >, ReadyType > > >::value () const &
 
value_type & pw::async2::FutureOrValue< FutureType, std::enable_if_t<!std::is_same_v< FutureValue< FutureType >, ReadyType > > >::operator* () &
 Accesses the stored value. Must only be called if has_value() is true.
 
const value_type & pw::async2::FutureOrValue< FutureType, std::enable_if_t<!std::is_same_v< FutureValue< FutureType >, ReadyType > > >::operator* () const &
 
value_type * pw::async2::FutureOrValue< FutureType, std::enable_if_t<!std::is_same_v< FutureValue< FutureType >, ReadyType > > >::operator-> ()
 
const value_type * pw::async2::FutureOrValue< FutureType, std::enable_if_t<!std::is_same_v< FutureValue< FutureType >, ReadyType > > >::operator-> () const
 
value_type pw::async2::FutureOrValue< FutureType, std::enable_if_t<!std::is_same_v< FutureValue< FutureType >, ReadyType > > >::Take ()
 
void pw::async2::FutureOrValue< FutureType, std::enable_if_t<!std::is_same_v< FutureValue< FutureType >, ReadyType > > >::Reset ()
 Cancels the operation by destroying the future and clearing any value.
 
 pw::async2::FutureOrValue< FutureType, std::enable_if_t< std::is_same_v< FutureValue< FutureType >, ReadyType > > >::FutureOrValue (FutureType &&future)
 
 pw::async2::FutureOrValue< FutureType, std::enable_if_t< std::is_same_v< FutureValue< FutureType >, ReadyType > > >::FutureOrValue (const FutureOrValue &)=delete
 
FutureOrValuepw::async2::FutureOrValue< FutureType, std::enable_if_t< std::is_same_v< FutureValue< FutureType >, ReadyType > > >::operator= (const FutureOrValue &)=delete
 
 pw::async2::FutureOrValue< FutureType, std::enable_if_t< std::is_same_v< FutureValue< FutureType >, ReadyType > > >::FutureOrValue (FutureOrValue &&)=default
 
FutureOrValuepw::async2::FutureOrValue< FutureType, std::enable_if_t< std::is_same_v< FutureValue< FutureType >, ReadyType > > >::operator= (FutureOrValue &&)=default
 
FutureOrValuepw::async2::FutureOrValue< FutureType, std::enable_if_t< std::is_same_v< FutureValue< FutureType >, ReadyType > > >::operator= (FutureType &&future)
 
bool pw::async2::FutureOrValue< FutureType, std::enable_if_t< std::is_same_v< FutureValue< FutureType >, ReadyType > > >::Advance (Context &cx)
 
bool pw::async2::FutureOrValue< FutureType, std::enable_if_t< std::is_same_v< FutureValue< FutureType >, ReadyType > > >::empty () const
 Returns true if neither a future nor its result is held.
 
bool pw::async2::FutureOrValue< FutureType, std::enable_if_t< std::is_same_v< FutureValue< FutureType >, ReadyType > > >::has_value () const
 Returns whether the value is available.
 
bool pw::async2::FutureOrValue< FutureType, std::enable_if_t< std::is_same_v< FutureValue< FutureType >, ReadyType > > >::has_future () const
 Returns whether an active future is stored and pending.
 
void pw::async2::FutureOrValue< FutureType, std::enable_if_t< std::is_same_v< FutureValue< FutureType >, ReadyType > > >::Take ()
 
void pw::async2::FutureOrValue< FutureType, std::enable_if_t< std::is_same_v< FutureValue< FutureType >, ReadyType > > >::Reset ()
 
template<typename... Ts>
bool pw::async2::internal::AdvanceAll (Context &cx, Ts &... ts)
 

Macro Definition Documentation

◆ PW_FOV_TRY_ADVANCE

#define PW_FOV_TRY_ADVANCE (   cx,
  ... 
)
Value:
do { \
if (!::pw::async2::internal::AdvanceAll((cx), __VA_ARGS__)) { \
return ::pw::async2::Pending(); \
} \
} while (0)

Macro to poll multiple FutureOrValue objects.

Returns Pending() if any of the provided slots are not ready. Ensures that all provided futures are polled.

Typedef Documentation

◆ FutureList

template<auto kMemberPtr>
using pw::async2::FutureList = typedef CustomFutureList<ContainerOf<kMemberPtr, FutureCore>, MemberOf<kMemberPtr> >

A CustomFutureList that uses a pointer to a FutureCore member.

Template Parameters
kMemberPtrpointer to a FutureCore member of a custom future class

◆ FutureValue

template<typename T >
using pw::async2::FutureValue = typedef std::conditional_t<std::is_void_v<typename T::value_type>, ReadyType, typename T::value_type>

The value type of the future. Maps void to ReadyType, so that FutureValue<Future> can always be instantiated and referenced. Use Future::value_type directly if void is preferable.

Function Documentation

◆ Advance()

template<typename FutureType >
bool pw::async2::FutureOrValue< FutureType, std::enable_if_t<!std::is_same_v< FutureValue< FutureType >, ReadyType > > >::Advance ( Context cx)
inline

Advances the stored future.

If the value is already available, returns true immediately. Otherwise, polls the future. If the future resolves, stores the value and returns true. If the future is pending, returns false.

◆ operator=()

template<typename FutureType >
FutureOrValue & pw::async2::FutureOrValue< FutureType, std::enable_if_t<!std::is_same_v< FutureValue< FutureType >, ReadyType > > >::operator= ( FutureType &&  future)
inline

Assigns a new future.

This destroys any existing future (cancelling it) and clears any stored value.

◆ Take()

template<typename FutureType >
value_type pw::async2::FutureOrValue< FutureType, std::enable_if_t<!std::is_same_v< FutureValue< FutureType >, ReadyType > > >::Take ( )
inline

Moves the value out and resets state to empty. Must only be called if has_value() is true.