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

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

#include <future.hpp>

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

Public Types

using Result = typename T::template Result< V >
 
using Handle = detail::UniqueHandle
 
using Core = detail::UniqueCore< V, T >
 

Public Member Functions

 FutureBase (const FutureBase &)=delete
 
FutureBaseoperator= (const FutureBase &)=delete
 
 FutureBase (FutureBase &&other) noexcept=default
 
FutureBaseoperator= (FutureBase &&other) noexcept=default
 
 FutureBase ()=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 ResultGet () const &noexcept
 Return copy of Result from Future.
 
Result Get () &&noexcept
 
const ResultTouch () const &noexcept
 
Result Touch () &&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::UniqueCorePtr< V, T > & GetCore () noexcept
 Method that get internal Core state.
 
detail::UniqueHandle GetHandle () noexcept
 

Protected Member Functions

 FutureBase (detail::UniqueCorePtr< V, T > core) noexcept
 

Protected Attributes

detail::UniqueCorePtr< V, T > _core
 

Detailed Description

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

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.

Member Typedef Documentation

◆ Core

template<typename V , typename T >
using yaclib::FutureBase< V, T >::Core = detail::UniqueCore<V, T>

Definition at line 191 of file future.hpp.

◆ Handle

template<typename V , typename T >
using yaclib::FutureBase< V, T >::Handle = detail::UniqueHandle

Definition at line 190 of file future.hpp.

◆ Result

template<typename V , typename T >
using yaclib::FutureBase< V, T >::Result = typename T::template Result<V>

Definition at line 26 of file future.hpp.

Constructor & Destructor Documentation

◆ FutureBase() [1/4]

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

◆ FutureBase() [2/4]

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

◆ FutureBase() [3/4]

template<typename V , typename T >
yaclib::FutureBase< V, T >::FutureBase ( )
default

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 T >
yaclib::FutureBase< V, T >::~FutureBase ( )
inlinenoexcept

If Future is Valid then call Stop.

Definition at line 46 of file future.hpp.

References yaclib::FutureBase< V, T >::Valid().

◆ FutureBase() [4/4]

template<typename V , typename T >
yaclib::FutureBase< V, T >::FutureBase ( detail::UniqueCorePtr< V, T >  core)
inlineexplicitprotectednoexcept

Definition at line 198 of file future.hpp.

Member Function Documentation

◆ Detach() [1/2]

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

Disable calling Stop in destructor.

Definition at line 146 of file future.hpp.

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

◆ Detach() [2/2]

template<typename V , typename T >
template<typename Func >
void yaclib::FutureBase< V, T >::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 174 of file future.hpp.

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

◆ DetachInline()

template<typename V , typename T >
template<typename Func >
void yaclib::FutureBase< V, T >::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 160 of file future.hpp.

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

◆ Get() [1/4]

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

Definition at line 96 of file future.hpp.

References yaclib::FutureBase< V, T >::_core, and yaclib::Wait().

◆ Get() [2/4]

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

◆ Get() [3/4]

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

◆ Get() [4/4]

template<typename V , typename T >
const Result * yaclib::FutureBase< V, T >::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 83 of file future.hpp.

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

◆ GetCore()

template<typename V , typename T >
detail::UniqueCorePtr< V, T > & yaclib::FutureBase< V, T >::GetCore ( )
inlinenoexcept

Method that get internal Core state.

Returns
internal Core state ptr

Definition at line 186 of file future.hpp.

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

◆ GetHandle()

template<typename V , typename T >
detail::UniqueHandle yaclib::FutureBase< V, T >::GetHandle ( )
inlinenoexcept

Definition at line 193 of file future.hpp.

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

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ Ready()

template<typename V , typename T >
bool yaclib::FutureBase< V, T >::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 66 of file future.hpp.

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

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

◆ Then()

template<typename V , typename T >
template<typename Func >
auto yaclib::FutureBase< V, T >::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 136 of file future.hpp.

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

◆ Touch() [1/4]

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

◆ Touch() [2/4]

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

◆ Touch() [3/4]

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

◆ Touch() [4/4]

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

◆ Valid()

template<typename V , typename T >
bool yaclib::FutureBase< V, T >::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 57 of file future.hpp.

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

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

Member Data Documentation

◆ _core


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