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

#include <future_fwd.hpp>

Public Types

typedef detail::FutureType< T >
::type 
ValueType
 

Public Member Functions

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

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 >
class ::qi::detail::FutureBaseTyped
 
template<typename R >
void adaptFutureUnwrap (Future< AnyReference > &f, Promise< R > &p)
 Feed a promise from a generic future which may be unwrapped if it contains itself a future. More...
 
template<typename FT , typename PT >
void adaptFuture (const Future< FT > &f, Promise< PT > &p)
 Feed a promise from a future of possibly different type. More...
 
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...
 
template<typename R >
void adaptFuture (Future< AnyReference > &f, Promise< R > &p)
 

Detailed Description

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

A Promise is used to create and satisfy a Future.

Definition at line 63 of file future_fwd.hpp.

Member Typedef Documentation

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

Definition at line 643 of file future_fwd.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 650 of file future_fwd.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 661 of file future_fwd.hpp.

template<typename T>
qi::Promise< T >::Promise ( const qi::Promise< T > &  rhs)
inline

Definition at line 668 of file future_fwd.hpp.

template<typename T>
qi::Promise< T >::~Promise ( )
inline

Definition at line 674 of file future_fwd.hpp.

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

Definition at line 750 of file future_fwd.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 708 of file future_fwd.hpp.

template<typename T>
bool qi::Promise< T >::isCancelRequested ( ) const
inline

return true if cancel has been called on the promise (even if the cancel callback did not run yet).

Definition at line 703 of file future_fwd.hpp.

template<typename T>
Promise<T>& qi::Promise< T >::operator= ( const Promise< T > &  rhs)
inline

Definition at line 732 of file future_fwd.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 696 of file future_fwd.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 689 of file future_fwd.hpp.

template<typename T>
void qi::Promise< T >::setOnCancel ( boost::function< void(qi::Promise< T >)>  cancelCallback)
inline

Set a cancel callback. If the cancel is requested, calls this callback immediately.

Exceptions
std::exceptionif the promise was not created as a cancelable promise.

Definition at line 724 of file future_fwd.hpp.

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

Definition at line 744 of file future_fwd.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 If T is void value must be 0

Definition at line 682 of file future_fwd.hpp.

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

Trigger the promise with the current value.

Definition at line 717 of file future_fwd.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 714 of file future_fwd.hpp.

Friends And Related Function Documentation

template<typename T>
template<typename >
friend class ::qi::detail::FutureBaseTyped
friend

Definition at line 753 of file future_fwd.hpp.

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 621 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 631 of file future.hxx.

template<typename T>
template<typename R >
void adaptFuture ( Future< AnyReference > &  f,
Promise< R > &  p 
)
friend
template<typename T>
template<typename R >
void adaptFutureUnwrap ( Future< AnyReference > &  f,
Promise< R > &  p 
)
friend

Feed a promise from a generic future which may be unwrapped if it contains itself a future.

Definition at line 610 of file future.hxx.

Member Data Documentation

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

Definition at line 754 of file future_fwd.hpp.


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