Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
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
 
Future & operator= (Future &&other)
 
template<typename Callback , typename... Args>
 Future (auto &taskManager, Callback &&callback, Args &&... args)
 Make the future wait for the result of callback. More...
 
 ~Future ()
 
ResultType Get ()
 Move the result out of the future, and invalidate the future. More...
 
bool IsDone () const
 
bool Valid () const
 
void Wait ()
 
void CancelOrWait ()
 

Protected Attributes

std::shared_ptr< FutureSharedStateDetail::Receiver< ResultType > > m_Receiver
 

Friends

template<typename T >
class PackagedTask
 

Detailed Description

template<typename ResultType>
class Future< ResultType >

Corresponds to std::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 callback never runs after the Future is destroyed.

Constructor & Destructor Documentation

◆ Future() [1/4]

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

◆ Future() [2/4]

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

◆ Future() [3/4]

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

◆ Future() [4/4]

template<typename ResultType >
template<typename Callback , typename... Args>
Future< ResultType >::Future ( auto &  taskManager,
Callback &&  callback,
Args &&...  args 
)
inline

Make the future wait for the result of callback.

◆ ~Future()

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

Member Function Documentation

◆ CancelOrWait()

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

◆ Get()

template<typename ResultType >
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 invalid, asserts.

◆ IsDone()

template<typename ResultType >
bool Future< ResultType >::IsDone ( ) 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 > &&  other)
inline

◆ 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

Friends And Related Function Documentation

◆ PackagedTask

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

Member Data Documentation

◆ m_Receiver

template<typename ResultType >
std::shared_ptr<FutureSharedStateDetail::Receiver<ResultType> > Future< ResultType >::m_Receiver
protected

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