libqi-api  2.8.7.4
 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

using ValueType = typename detail::FutureType< T >::type
 

Public Member Functions

 Promise (FutureCallbackType async=FutureCallbackType_Auto)
 
template<typename FUNC , typename std::enable_if<!std::is_same< typename std::decay< FUNC >::type, typename std::decay< qi::Promise< T > >::type >::value >::type * = nullptr>
 Promise (FUNC &&cancelCallback, FutureCallbackType async=FutureCallbackType_Auto)
 
 Promise (boost::function< void(qi::Promise< T >)> cancelCallback, FutureCallbackType async=FutureCallbackType_Auto)
 
 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...
 
ValueTypevalue ()
 
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_Auto)
 
 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, AdaptFutureOption option)
 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, AdaptFutureOption option)
 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 71 of file future_fwd.hpp.

Member Typedef Documentation

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

Definition at line 803 of file future_fwd.hpp.

Constructor & Destructor Documentation

template<typename T>
qi::Promise< T >::Promise ( FutureCallbackType  async = FutureCallbackType_Auto)
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 810 of file future_fwd.hpp.

template<typename T>
template<typename FUNC , typename std::enable_if<!std::is_same< typename std::decay< FUNC >::type, typename std::decay< qi::Promise< T > >::type >::value >::type * = nullptr>
qi::Promise< T >::Promise ( FUNC &&  cancelCallback,
FutureCallbackType  async = FutureCallbackType_Auto 
)
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 827 of file future_fwd.hpp.

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

Definition at line 834 of file future_fwd.hpp.

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

Definition at line 841 of file future_fwd.hpp.

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

Definition at line 847 of file future_fwd.hpp.

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

Definition at line 921 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 881 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 876 of file future_fwd.hpp.

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

Definition at line 903 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 869 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 862 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 897 of file future_fwd.hpp.

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

Definition at line 915 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 nullptr

Definition at line 855 of file future_fwd.hpp.

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

Trigger the promise with the current value.

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

Friends And Related Function Documentation

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

Definition at line 924 of file future_fwd.hpp.

template<typename T>
template<typename FT , typename PT >
void adaptFuture ( const Future< FT > &  f,
Promise< PT > &  p,
AdaptFutureOption  option 
)
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 537 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,
AdaptFutureOption  option 
)
friend

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

Definition at line 547 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 528 of file future.hxx.

Member Data Documentation

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

Definition at line 925 of file future_fwd.hpp.


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