libqi-api  2.1.4.13
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
qi::Promise< T > Class Template Reference

#include <future.hpp>

Public Types

typedef FutureType< T >::type ValueType
 

Public Member Functions

 Promise (FutureCallbackType async=FutureCallbackType_Async)
 
 Promise (boost::function< void(qi::Promise< T >)> cancelCallback, FutureCallbackType async=FutureCallbackType_Async)
 
void setValue (const ValueType &value)
 
void setError (const std::string &msg)
 
void setCanceled ()
 
void reset ()
 
Future< T > future () const
 Get a future linked to this promise. Can be called multiple times. More...
 
ValueTypevalue ()
 
void trigger ()
 

Protected Member Functions

void setup (boost::function< void(qi::Promise< T >)> cancelCallback, FutureCallbackType async=FutureCallbackType_Async)
 
 Promise (Future< T > &f)
 

Protected Attributes

Future< T > _f
 

Friends

template<typename FT , typename PT >
void adaptFuture (const Future< FT > &f, Promise< PT > &p)
 
template<typename FT , typename PT , typename CONV >
void adaptFuture (const Future< FT > &f, Promise< PT > &p, CONV converter)
 Similar to adaptFuture(f, p) but with a custom converter. More...
 

Detailed Description

template<typename T>
class qi::Promise< T >

A Promise is used to create and satisfy a Future.

Definition at line 49 of file future.hpp.

Member Typedef Documentation

template<typename T>
typedef FutureType<T>::type qi::Promise< T >::ValueType

Definition at line 444 of file future.hpp.

Constructor & Destructor Documentation

template<typename T>
qi::Promise< T >::Promise ( FutureCallbackType  async = FutureCallbackType_Async)
inlineexplicit

Create a standard promise.

Parameters
asyncspecify how callbacks registered with Future::connect are called: synchronously from the Promise setter, or asynchronously from a thread pool.

Definition at line 451 of file future.hpp.

template<typename T>
qi::Promise< T >::Promise ( boost::function< void(qi::Promise< T >)>  cancelCallback,
FutureCallbackType  async = FutureCallbackType_Async 
)
inlineexplicit

Create a canceleable promise. If Future<T>::cancel is invoked, onCancel() will be called. It is expected to call setValue(), setError() or setCanceled() as quickly as possible, but can do so in an asynchronous way.

Definition at line 461 of file future.hpp.

template<typename T>
qi::Promise< T >::Promise ( Future< T > &  f)
inlineexplicitprotected

Definition at line 509 of file future.hpp.

Member Function Documentation

template<typename T>
Future<T> qi::Promise< T >::future ( ) const
inline

Get a future linked to this promise. Can be called multiple times.

Definition at line 493 of file future.hpp.

template<typename T>
void qi::Promise< T >::reset ( )
inline

Definition at line 488 of file future.hpp.

template<typename T>
void qi::Promise< T >::setCanceled ( )
inline

set the cancel state, and notify all futures throw if state != running

Definition at line 483 of file future.hpp.

template<typename T>
void qi::Promise< T >::setError ( const std::string &  msg)
inline

set the error, and notify all futures throw if state != running

Definition at line 476 of file future.hpp.

template<typename T>
void qi::Promise< T >::setup ( boost::function< void(qi::Promise< T >)>  cancelCallback,
FutureCallbackType  async = FutureCallbackType_Async 
)
inlineprotected

Definition at line 503 of file future.hpp.

template<typename T>
void qi::Promise< T >::setValue ( const ValueType value)
inline

notify all future that a value has been set. throw if state != running

Definition at line 469 of file future.hpp.

template<typename T>
void qi::Promise< T >::trigger ( )
inline

Trigger the promise with the current value.

Definition at line 501 of file future.hpp.

template<typename T>
ValueType& qi::Promise< T >::value ( )
inline

Gives access to the underlying value for in-place modification. trigger() must be called after the value is written to trigger the promise.

Definition at line 498 of file future.hpp.

Friends And Related Function Documentation

template<typename T>
template<typename FT , typename PT >
void adaptFuture ( const Future< FT > &  f,
Promise< PT > &  p 
)
friend

Feed a promise from a future of possibly different type. Will monitor f, and bounce its state to p. Error and canceled state are bounced as is. Valued state is bounced through FutureValueConverter<FT, PT>::convert()

Definition at line 316 of file future.hxx.

template<typename T>
template<typename FT , typename PT , typename CONV >
void adaptFuture ( const Future< FT > &  f,
Promise< PT > &  p,
CONV  converter 
)
friend

Similar to adaptFuture(f, p) but with a custom converter.

Definition at line 326 of file future.hxx.

Member Data Documentation

template<typename T>
Future<T> qi::Promise< T >::_f
protected

Definition at line 511 of file future.hpp.


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