YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
yaclib::FutureBase< V, E > Class Template Reference

Provides a mechanism to access the result of async operations. More...

#include <future.hpp>

Inheritance diagram for yaclib::FutureBase< V, E >:
[legend]
Collaboration diagram for yaclib::FutureBase< V, E >:
[legend]

Public Member Functions

 FutureBase (const FutureBase &)=delete
 
FutureBaseoperator= (const FutureBase &)=delete
 
 FutureBase (FutureBase &&other) noexcept=default
 
FutureBaseoperator= (FutureBase &&other) noexcept=default
 
 FutureBase () noexcept=default
 The default constructor creates not a Valid Future.
 
 ~FutureBase () noexcept
 If Future is Valid then call Stop.
 
bool Valid () const &noexcept
 Check if this Future has Promise.
 
bool Ready () const &noexcept
 Check that Result that corresponds to this Future is computed.
 
void Get () &=delete
 
void Get () const &&=delete
 
void Touch () &=delete
 
void Touch () const &&=delete
 
const Result< V, E > * Get () const &noexcept
 Return copy of Result from Future.
 
Result< V, EGet () &&noexcept
 
const Result< V, E > & Touch () const &noexcept
 
Result< V, ETouch () &&noexcept
 
template<typename Func >
auto Then (IExecutor &e, Func &&f) &&
 Attach the continuation func to *this.
 
void Detach () &&noexcept
 Disable calling Stop in destructor.
 
template<typename Func >
void DetachInline (Func &&f) &&
 Attach the final continuation func to *this and Detach *this.
 
template<typename Func >
void Detach (IExecutor &e, Func &&f) &&
 Attach the final continuation func to *this and Detach *this.
 
detail::ResultCorePtr< V, E > & GetCore () noexcept
 Method that get internal Core state.
 

Protected Member Functions

 FutureBase (detail::ResultCorePtr< V, E > core) noexcept
 

Protected Attributes

detail::ResultCorePtr< V, E_core
 

Detailed Description

template<typename V, typename E>
class yaclib::FutureBase< V, E >

Provides a mechanism to access the result of async operations.

Future and Promise are like a Single Producer/Single Consumer one-shot one-element channel. Use the Promise to fulfill the Future.

Definition at line 20 of file future.hpp.

Constructor & Destructor Documentation

◆ FutureBase() [1/4]

template<typename V , typename E >
yaclib::FutureBase< V, E >::FutureBase ( const FutureBase< V, E > &  )
delete

◆ FutureBase() [2/4]

template<typename V , typename E >
yaclib::FutureBase< V, E >::FutureBase ( FutureBase< V, E > &&  other)
defaultnoexcept

◆ FutureBase() [3/4]

template<typename V , typename E >
yaclib::FutureBase< V, E >::FutureBase ( )
defaultnoexcept

The default constructor creates not a Valid Future.

Needed only for usability, e.g. instead of std::optional<Future<T>> in containers.

◆ ~FutureBase()

template<typename V , typename E >
yaclib::FutureBase< V, E >::~FutureBase ( )
inlinenoexcept

If Future is Valid then call Stop.

Definition at line 42 of file future.hpp.

References yaclib::FutureBase< V, E >::Detach(), and yaclib::FutureBase< V, E >::Valid().

◆ FutureBase() [4/4]

template<typename V , typename E >
yaclib::FutureBase< V, E >::FutureBase ( detail::ResultCorePtr< V, E core)
inlineexplicitprotectednoexcept

Definition at line 184 of file future.hpp.

References yaclib::MakeContract().

Member Function Documentation

◆ Detach() [1/2]

template<typename V , typename E >
void yaclib::FutureBase< V, E >::Detach ( ) &&
inlinenoexcept

Disable calling Stop in destructor.

Definition at line 141 of file future.hpp.

References yaclib::FutureBase< V, E >::_core, yaclib::MakeContract(), and yaclib::detail::MakeDrop().

Referenced by yaclib::FutureBase< V, E >::~FutureBase().

◆ Detach() [2/2]

template<typename V , typename E >
template<typename Func >
void yaclib::FutureBase< V, E >::Detach ( IExecutor e,
Func &&  f 
) &&
inline

Attach the final continuation func to *this and Detach *this.

The func will be executed on the specified executor.

Note
The behavior is undefined if Valid is false before the call to this function.
Parameters
eExecutor which will Execute the continuation
fA continuation to be attached

Definition at line 168 of file future.hpp.

References yaclib::FutureBase< V, E >::_core, yaclib::IExecutor::Inline, yaclib::MakeContract(), and YACLIB_WARN.

◆ DetachInline()

template<typename V , typename E >
template<typename Func >
void yaclib::FutureBase< V, E >::DetachInline ( Func &&  f) &&
inline

Attach the final continuation func to *this and Detach *this.

The func will be executed on Inline executor.

Note
The behavior is undefined if Valid is false before the call to this function.
Parameters
fA continuation to be attached

Definition at line 155 of file future.hpp.

References yaclib::FutureBase< V, E >::_core, and yaclib::MakeContract().

◆ Get() [1/4]

template<typename V , typename E >
Result< V, E > yaclib::FutureBase< V, E >::Get ( ) &&
inlinenoexcept

◆ Get() [2/4]

template<typename V , typename E >
void yaclib::FutureBase< V, E >::Get ( ) &
delete

◆ Get() [3/4]

template<typename V , typename E >
void yaclib::FutureBase< V, E >::Get ( ) const &&
delete

◆ Get() [4/4]

template<typename V , typename E >
const Result< V, E > * yaclib::FutureBase< V, E >::Get ( ) const &
inlinenoexcept

Return copy of Result from Future.

If Ready is false return an empty Result. This method is thread-safe and can be called multiple times.

Note
The behavior is undefined if Valid is false before the call to this function.
Returns
Result stored in the shared state

Definition at line 79 of file future.hpp.

References yaclib::FutureBase< V, E >::_core, and yaclib::FutureBase< V, E >::Ready().

◆ GetCore()

template<typename V , typename E >
detail::ResultCorePtr< V, E > & yaclib::FutureBase< V, E >::GetCore ( )
inlinenoexcept

Method that get internal Core state.

Returns
internal Core state ptr

Definition at line 179 of file future.hpp.

References yaclib::FutureBase< V, E >::_core.

◆ operator=() [1/2]

template<typename V , typename E >
FutureBase & yaclib::FutureBase< V, E >::operator= ( const FutureBase< V, E > &  )
delete

◆ operator=() [2/2]

template<typename V , typename E >
FutureBase & yaclib::FutureBase< V, E >::operator= ( FutureBase< V, E > &&  other)
defaultnoexcept

◆ Ready()

template<typename V , typename E >
bool yaclib::FutureBase< V, E >::Ready ( ) const &
inlinenoexcept

Check that Result that corresponds to this Future is computed.

Returns
false if the Result of this Future is not computed yet, otherwise true

Definition at line 62 of file future.hpp.

References yaclib::FutureBase< V, E >::_core, yaclib::FutureBase< V, E >::Valid(), and YACLIB_ASSERT.

Referenced by yaclib::FutureBase< V, E >::Get(), yaclib::FutureBase< V, E >::Touch(), and yaclib::FutureBase< V, E >::Touch().

◆ Then()

template<typename V , typename E >
template<typename Func >
auto yaclib::FutureBase< V, E >::Then ( IExecutor e,
Func &&  f 
) &&
inline

Attach the continuation func to *this.

The func will be executed on the specified executor.

Note
The behavior is undefined if Valid is false before the call to this function.
Parameters
eExecutor which will Execute the continuation
fA continuation to be attached
Returns
New FutureOn object associated with the func result

Definition at line 132 of file future.hpp.

References yaclib::FutureBase< V, E >::_core, yaclib::IExecutor::Inline, yaclib::MakeContract(), and YACLIB_WARN.

◆ Touch() [1/4]

template<typename V , typename E >
Result< V, E > yaclib::FutureBase< V, E >::Touch ( ) &&
inlinenoexcept

◆ Touch() [2/4]

template<typename V , typename E >
void yaclib::FutureBase< V, E >::Touch ( ) &
delete

◆ Touch() [3/4]

template<typename V , typename E >
void yaclib::FutureBase< V, E >::Touch ( ) const &&
delete

◆ Touch() [4/4]

template<typename V , typename E >
const Result< V, E > & yaclib::FutureBase< V, E >::Touch ( ) const &
inlinenoexcept

◆ Valid()

template<typename V , typename E >
bool yaclib::FutureBase< V, E >::Valid ( ) const &
inlinenoexcept

Check if this Future has Promise.

Returns
false if this Future is default-constructed or moved to, otherwise true
Examples
simple.cpp.

Definition at line 53 of file future.hpp.

References yaclib::FutureBase< V, E >::_core.

Referenced by yaclib::FutureBase< V, E >::Ready(), TEST(), and yaclib::FutureBase< V, E >::~FutureBase().

Member Data Documentation

◆ _core


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