MEL
Microthread & Execution library
mel::core::Future< T > Class Template Reference

Represents a value that maybe is not present at the current moment. More...

#include <Future.h>

Inheritance diagram for mel::core::Future< T >:
mel::core::Future_Common< T > mel::execution::ExFuture< ExecutorAgent, TArg > mel::execution::ExFuture< ExecutorAgent, ResultType >

Public Types

typedef _private::FutureData< T >::ValueType ValueType
 

Public Member Functions

 Future (const Future &f) noexcept
 
 Future (Future &&f) noexcept
 
 Future (const T &val)
 
 Future (T &&val)
 
Futureoperator= (const Future &f) noexcept
 
Futureoperator= (Future &&f) noexcept
 
template<class F >
void setValue (F &&value)
 
template<class F >
void setError (F &&ei)
 
const _private::FutureData< T >::ValueType & getValue () const
 Get the Value object. More...
 
_private::FutureData< T >::ValueType & getValue ()
 Get the Value object. More...
 
void assign (const typename _private::FutureData< T >::ValueType &val)
 
void assign (typename _private::FutureData< T >::ValueType &&val)
 
void assign (Future_Common< T > val)
 Makes this Future to point to the same value as the given Future. More...
 
template<class F >
int subscribeCallback (F &&f) const
 Subscribe callback to be executed when future is ready (valid or error) More...
 
int unsubscribeCallback (int id) const
 Unsubscribe given callback. More...
 

Detailed Description

template<typename T>
class mel::core::Future< T >

Represents a value that maybe is not present at the current moment.

This value will be generated by someone and will be available at "some moment" The value is retrieved using various ways:

callback notification with Future_Common::subscribeCallback should check getValid, in which case there is an error ( see error )

Member Function Documentation

◆ assign()

template<typename T >
void mel::core::Future_Common< T >::assign ( Future_Common< T >  val)
inlineinherited

Makes this Future to point to the same value as the given Future.

This ways, both futures will share the same value/error. If input Future is already set at that moment, callbacks are triggered as usual. It's important to note that all futures sharing same data will change

◆ getValue() [1/2]

template<typename T >
_private::FutureData<T>::ValueType& mel::core::Future_Common< T >::getValue ( )
inlineinherited

Get the Value object.

Returns
const mel::core::FutureValue

◆ getValue() [2/2]

template<typename T >
const _private::FutureData<T>::ValueType& mel::core::Future_Common< T >::getValue ( ) const
inlineinherited

Get the Value object.

Returns
const mel::core::FutureValue

◆ subscribeCallback()

template<typename T >
template<class F >
int mel::core::Future_Common< T >::subscribeCallback ( F &&  f) const
inlineinherited

Subscribe callback to be executed when future is ready (valid or error)

Parameters
[in]FCallable with signature void( \ref mel::core::FutureValue& )
Warning
Usually callback is executed in the context of the thread doing setValue, but if Future is already ready callback will be executed in the context of the thread doing subscription. In general, for this and more reasons, callbacks responses should be done buy launchin a task, so decoupliing totally the diferent tasks
Returns
callback id

◆ unsubscribeCallback()

template<typename T >
int mel::core::Future_Common< T >::unsubscribeCallback ( int  id) const
inlineinherited

Unsubscribe given callback.

because use of lambda, unsubscription can only be done by id (returned by subscribeCallback)


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