WPILibC++ 2024.3.2
wpi::future< T > Class Template Reference

A lightweight version of std::future. More...

#include <wpi/future.h>

Public Member Functions

 future () noexcept=default
 Constructs an empty (invalid) future. More...
 
 future (future &&oth) noexcept
 
 future (const future &)=delete
 
template<typename R >
 future (future< R > &&oth) noexcept
 
 ~future ()
 Ignores the result of the future if it has not been retrieved. More...
 
futureoperator= (future &&oth) noexcept
 
futureoperator= (const future &)=delete
 
get ()
 Gets the value. More...
 
template<typename R , typename F >
future< R > then (PromiseFactory< R > &factory, F &&func)
 
template<typename F , typename R = typename std::invoke_result_t<F&&, T&&>>
future< R > then (F &&func)
 
bool is_ready () const noexcept
 
bool valid () const noexcept
 Checks if the future is valid. More...
 
void wait () const
 Waits for the promise to provide a value. More...
 
template<class Clock , class Duration >
bool wait_until (const std::chrono::time_point< Clock, Duration > &timeout_time) const
 Waits for the promise to provide a value, or the specified time has been reached. More...
 
template<class Rep , class Period >
bool wait_for (const std::chrono::duration< Rep, Period > &timeout_duration) const
 Waits for the promise to provide a value, or the specified amount of time has elapsed. More...
 

Friends

class PromiseFactory< T >
 
class promise< T >
 

Detailed Description

template<typename T>
class wpi::future< T >

A lightweight version of std::future.

Use either promise::get_future() or PromiseFactory::CreateFuture() to create.

Template Parameters
Tthe "return" type

Constructor & Destructor Documentation

◆ future() [1/4]

template<typename T >
wpi::future< T >::future ( )
defaultnoexcept

Constructs an empty (invalid) future.

◆ future() [2/4]

template<typename T >
wpi::future< T >::future ( future< T > &&  oth)
inlinenoexcept

◆ future() [3/4]

template<typename T >
wpi::future< T >::future ( const future< T > &  )
delete

◆ future() [4/4]

template<typename T >
template<typename R >
wpi::future< T >::future ( future< R > &&  oth)
inlinenoexcept

◆ ~future()

template<typename T >
wpi::future< T >::~future ( )
inline

Ignores the result of the future if it has not been retrieved.

Member Function Documentation

◆ get()

template<typename T >
T wpi::future< T >::get ( )
inline

Gets the value.

Calls wait() if the value is not yet available. Can only be called once. The future will be marked invalid after the call.

Returns
The value provided by the corresponding promise.set_value().

◆ is_ready()

template<typename T >
bool wpi::future< T >::is_ready ( ) const
inlinenoexcept

◆ operator=() [1/2]

template<typename T >
future & wpi::future< T >::operator= ( const future< T > &  )
delete

◆ operator=() [2/2]

template<typename T >
future & wpi::future< T >::operator= ( future< T > &&  oth)
inlinenoexcept

◆ then() [1/2]

template<typename T >
template<typename F , typename R = typename std::invoke_result_t<F&&, T&&>>
future< R > wpi::future< T >::then ( F &&  func)
inline

◆ then() [2/2]

template<typename T >
template<typename R , typename F >
future< R > wpi::future< T >::then ( PromiseFactory< R > &  factory,
F &&  func 
)
inline

◆ valid()

template<typename T >
bool wpi::future< T >::valid ( ) const
inlinenoexcept

Checks if the future is valid.

A default-constructed future or one where get() has been called is invalid.

Returns
True if valid

◆ wait()

template<typename T >
void wpi::future< T >::wait ( ) const
inline

Waits for the promise to provide a value.

Does not return until the value is available or the promise is destroyed (in which case a default-constructed value is "returned"). If the value has already been provided, returns immediately.

◆ wait_for()

template<typename T >
template<class Rep , class Period >
bool wpi::future< T >::wait_for ( const std::chrono::duration< Rep, Period > &  timeout_duration) const
inline

Waits for the promise to provide a value, or the specified amount of time has elapsed.

Returns
True if the promise provided a value, false if timed out.

◆ wait_until()

template<typename T >
template<class Clock , class Duration >
bool wpi::future< T >::wait_until ( const std::chrono::time_point< Clock, Duration > &  timeout_time) const
inline

Waits for the promise to provide a value, or the specified time has been reached.

Returns
True if the promise provided a value, false if timed out.

Friends And Related Function Documentation

◆ promise< T >

template<typename T >
friend class promise< T >
friend

◆ PromiseFactory< T >

template<typename T >
friend class PromiseFactory< T >
friend

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