RSC  0.16.0
rsc::threading::Future< R > Class Template Reference

Class providing access to the result of a process that is asynchronously running. More...

#include <Future.h>

Collaboration diagram for rsc::threading::Future< R >:
Collaboration graph

Public Member Functions

 Future ()
 Create a new Future object that does not have a result and is thus suitable for representing an in-progress computation. More...
 
get ()
 Try to obtain and then return the result of the operation represented by the Future object. More...
 
get (double timeout)
 Try to obtain and then return the result of the operation represented by the Future object. More...
 
bool isDone ()
 Tells whether the computation of the underlying process finished and provided a result or generated an error. More...
 
void set (R data)
 Provide the result for this future. More...
 
void setError (const std::string &message)
 Indicate an error while processing. More...
 

Protected Types

typedef boost::mutex MutexType
 
typedef boost::condition ConditionType
 

Protected Member Functions

MutexTypegetMutex ()
 
ConditionTypegetCondition ()
 

Private Attributes

result
 
bool taskFinished
 
bool taskError
 
std::string errorMsg
 
ConditionType condition
 
MutexType mutex
 

Detailed Description

template<class R>
class rsc::threading::Future< R >

Class providing access to the result of a process that is asynchronously running.

If the result is requested before the task finished, the ::get operation will block until a results or error is available.

Author
jwienke
Template Parameters
Rresult type, should be copyable but this is not a hard requirement

Definition at line 99 of file Future.h.

Member Typedef Documentation

template<class R >
typedef boost::condition rsc::threading::Future< R >::ConditionType
protected

Definition at line 102 of file Future.h.

template<class R >
typedef boost::mutex rsc::threading::Future< R >::MutexType
protected

Definition at line 101 of file Future.h.

Constructor & Destructor Documentation

template<class R >
rsc::threading::Future< R >::Future ( )
inline

Create a new Future object that does not have a result and is thus suitable for representing an in-progress computation.

Definition at line 116 of file Future.h.

Member Function Documentation

template<class R >
R rsc::threading::Future< R >::get ( )
inline

Try to obtain and then return the result of the operation represented by the Future object.

If necessary, this method waits for the operation to complete, and then retrieves its result.

Returns
The result of the operation if it did complete successfully.
Exceptions
FutureTaskExecutionExceptionIf the operation represented by the Future object failed.

Definition at line 131 of file Future.h.

template<class R >
R rsc::threading::Future< R >::get ( double  timeout)
inline

Try to obtain and then return the result of the operation represented by the Future object.

If necessary, this method waits up to timeout seconds for the operation to complete. If the operation does not complete within this time a FutureTimeoutException is thrown.

Parameters
timeoutThe amount of time in seconds in which the operation has to complete.
Returns
The result of the operation if it did complete successfully within the given amount of time.
Exceptions
FutureTaskExecutionExceptionIf the operation represented by the Future object failed.
FutureTimeoutExceptionIf the result does not become available within the amount of time specified via timeout.

Definition at line 153 of file Future.h.

template<class R >
ConditionType& rsc::threading::Future< R >::getCondition ( )
inlineprotected

Definition at line 228 of file Future.h.

template<class R >
MutexType& rsc::threading::Future< R >::getMutex ( )
inlineprotected

Definition at line 224 of file Future.h.

template<class R >
bool rsc::threading::Future< R >::isDone ( )
inline

Tells whether the computation of the underlying process finished and provided a result or generated an error.

Returns
true if a result or error is available, else false

Definition at line 190 of file Future.h.

template<class R >
void rsc::threading::Future< R >::set ( data)
inline

Provide the result for this future.

Parameters
dataresult data

Definition at line 200 of file Future.h.

template<class R >
void rsc::threading::Future< R >::setError ( const std::string &  message)
inline

Indicate an error while processing.

Parameters
messageerror description

Definition at line 214 of file Future.h.

Member Data Documentation

template<class R >
ConditionType rsc::threading::Future< R >::condition
private

Definition at line 108 of file Future.h.

template<class R >
std::string rsc::threading::Future< R >::errorMsg
private

Definition at line 107 of file Future.h.

template<class R >
MutexType rsc::threading::Future< R >::mutex
private

Definition at line 109 of file Future.h.

template<class R >
R rsc::threading::Future< R >::result
private

Definition at line 104 of file Future.h.

template<class R >
bool rsc::threading::Future< R >::taskError
private

Definition at line 106 of file Future.h.

template<class R >
bool rsc::threading::Future< R >::taskFinished
private

Definition at line 105 of file Future.h.


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