libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
Future< T > Class Template Reference

Asynchronous result wrapping std::future<T>. More...

#include <future.h>

Public Member Functions

 Future ()=default
 Constructs an invalid (empty) Future.
 
 Future (std::future< T > &&f)
 Constructs a Future from a std::future.
 
 ~Future ()=default
 Destructor.
 
 Future (const Future &)=delete
 
Futureoperator= (const Future &)=delete
 
 Future (Future &&other)=default
 Move constructor.
 
Futureoperator= (Future &&other)=default
 Move assignment.
 
bool isReady () const
 Checks whether the result is ready without blocking.
 
Result< Tresult (unsigned int timeoutMs=0)
 Returns the result, blocking until available or timeout.
 
void waitForFinished ()
 Blocks until the result is ready.
 
Error waitForFinished (unsigned int timeoutMs)
 Blocks until the result is ready or the timeout expires.
 
bool isValid () const
 Returns whether this Future holds a valid shared state.
 

Detailed Description

template<typename T>
class Future< T >

Asynchronous result wrapping std::future<T>.

Returned by Promise<T>::future() and ThreadPool::submit().

Example
Promise<int> promise;
Future<int> future = promise.%future();
// In another thread:
promise.setValue(42);
// In the waiting thread:
int result = future.get(); // 42
Result< T > result(unsigned int timeoutMs=0)
Returns the result, blocking until available or timeout.
Definition future.h:76
Dynamic array container wrapping std::vector.
Definition list.h:40
Move-only (non-copyable).
Template Parameters
TThe result type.

Member Function Documentation

◆ isReady()

template<typename T >
bool Future< T >::isReady ( ) const
inline

Checks whether the result is ready without blocking.

Returns
True if the result is available.

◆ isValid()

template<typename T >
bool Future< T >::isValid ( ) const
inline

Returns whether this Future holds a valid shared state.

Returns
True if a result can be retrieved.

◆ result()

template<typename T >
Result< T > Future< T >::result ( unsigned int  timeoutMs = 0)
inline

Returns the result, blocking until available or timeout.

Parameters
timeoutMsMaximum time to wait in milliseconds. A value of 0 (the default) waits indefinitely.
Returns
A Result containing the value and Error::Ok, or a default-constructed T and Error::Timeout on timeout.

◆ waitForFinished()

template<typename T >
Error Future< T >::waitForFinished ( unsigned int  timeoutMs)
inline

Blocks until the result is ready or the timeout expires.

Parameters
timeoutMsMaximum time to wait in milliseconds.
Returns
Error::Ok if finished, Error::Timeout if the timeout elapsed.

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