Pyrogenesis  trunk
Public Member Functions | Protected Attributes | Private Types | Static Private Attributes | Friends | List of all members
Future< ResultType > Class Template Reference

Corresponds to std::future. More...

#include <Future.h>

Public Member Functions

 Future ()=default
 
 Future (const Future &o)=delete
 
 Future (Future &&)=default
 
Futureoperator= (Future &&)=default
 
 ~Future ()=default
 
template<typename T >
PackagedTask< ResultType > Wrap (T &&func)
 Make the future wait for the result of func. More...
 
template<typename SfinaeType = ResultType>
std::enable_if_t<!std::is_same_v< SfinaeType, void >, ResultType > Get ()
 Move the result out of the future, and invalidate the future. More...
 
bool IsReady () const
 
bool Valid () const
 
void Wait ()
 
void CancelOrWait ()
 Cancels the task, waiting if the task is currently started. More...
 

Protected Attributes

std::shared_ptr< SharedStatem_SharedState
 

Private Types

using Status = FutureSharedStateDetail::Status
 
using SharedState = FutureSharedStateDetail::SharedState< ResultType >
 

Static Private Attributes

static constexpr bool VoidResult = std::is_same_v<ResultType, void>
 

Friends

template<typename T >
class PackagedTask
 

Detailed Description

template<typename ResultType>
class Future< ResultType >

Corresponds to std::future.

Lightweight header / forward declarations for Future.

Unlike std::future, Future can request the cancellation of the task that would produce the result. This makes it more similar to Java's CancellableTask or C#'s Task. The name Future was kept over Task so it would be more familiar to C++ users, but this all should be revised once Concurrency TS wraps up.

Future is not thread-safe. Call it from a single thread or ensure synchronization externally.

The destructor is never blocking. The promise may still be running on destruction. TODO:

Include this in your header files where possible.

Member Typedef Documentation

◆ SharedState

template<typename ResultType>
using Future< ResultType >::SharedState = FutureSharedStateDetail::SharedState<ResultType>
private

◆ Status

template<typename ResultType>
using Future< ResultType >::Status = FutureSharedStateDetail::Status
private

Constructor & Destructor Documentation

◆ Future() [1/3]

template<typename ResultType>
Future< ResultType >::Future ( )
default

◆ Future() [2/3]

template<typename ResultType>
Future< ResultType >::Future ( const Future< ResultType > &  o)
delete

◆ Future() [3/3]

template<typename ResultType>
Future< ResultType >::Future ( Future< ResultType > &&  )
default

◆ ~Future()

template<typename ResultType>
Future< ResultType >::~Future ( )
default

Member Function Documentation

◆ CancelOrWait()

template<typename ResultType>
void Future< ResultType >::CancelOrWait ( )
inline

Cancels the task, waiting if the task is currently started.

Use this function over Cancel() if you need to ensure determinism (i.e. in the simulation).

See also
Cancel.

◆ Get()

template<typename ResultType>
template<typename SfinaeType = ResultType>
std::enable_if_t<!std::is_same_v<SfinaeType, void>, ResultType> Future< ResultType >::Get ( )
inline

Move the result out of the future, and invalidate the future.

If the future is not complete, calls Wait(). If the future is canceled, asserts.

◆ IsReady()

template<typename ResultType>
bool Future< ResultType >::IsReady ( ) const
inline
Returns
true if the shared state is valid and has a result (i.e. Get can be called).

◆ operator=()

template<typename ResultType>
Future& Future< ResultType >::operator= ( Future< ResultType > &&  )
default

◆ Valid()

template<typename ResultType>
bool Future< ResultType >::Valid ( ) const
inline
Returns
true if the future has a shared state and it's not been invalidated, ie. pending, started or done.

◆ Wait()

template<typename ResultType>
void Future< ResultType >::Wait ( )
inline

◆ Wrap()

template<typename ResultType >
template<typename T >
PackagedTask< ResultType > Future< ResultType >::Wrap ( T &&  func)

Make the future wait for the result of func.

Friends And Related Function Documentation

◆ PackagedTask

template<typename ResultType>
template<typename T >
friend class PackagedTask
friend

Member Data Documentation

◆ m_SharedState

template<typename ResultType>
std::shared_ptr<SharedState> Future< ResultType >::m_SharedState
protected

◆ VoidResult

template<typename ResultType>
constexpr bool Future< ResultType >::VoidResult = std::is_same_v<ResultType, void>
staticprivate

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