AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
aui::impl::future::Future< Value >::Inner Struct Reference

Public Member Functions

 Inner (std::function< Value()> task) noexcept
 
void waitForTask () noexcept
 
bool isWaitNeeded () noexcept
 
bool hasResult () const noexcept
 
bool hasValue () const noexcept
 
bool setThread (_< AAbstractThread > thr) noexcept
 
void wait (const _weak< CancellationWrapper< Inner > > &innerWeak, ABitField< AFutureWait > flags=AFutureWait::DEFAULT) noexcept
 
void cancel () noexcept
 
bool tryExecute (const _weak< CancellationWrapper< Inner > > &innerWeak)
 Executes the task stored in the future. Using weak_ptr to internal object in order to make possible Future cancellation by it's destruction.
 
void reportInterrupted () noexcept
 
void reportException (std::exception_ptr causedBy=std::current_exception()) noexcept
 
void notifyOnSuccessCallback (std::unique_lock< decltype(mutex)> &lock) noexcept
 Calls onSuccess callback.
 
template<typename F>
void invokeOnSuccessCallback (F &&f)
 
template<typename Callback>
void addOnSuccessCallback (Callback &&callback)
 
template<typename Callback>
void addOnErrorCallback (Callback &&callback)
 

Signals and public fields

bool interrupted = false
 
std::conditional_t< isVoid, bool, AOptional< Value > > value
 
AOptional< AInvocationTargetExceptionexception
 
ASpinlockMutex mutex
 
AConditionVariable cv
 
TaskCallback task
 
OnSuccessCallback onSuccess
 
std::function< void(const AException &exception)> onError
 
_< AAbstractThreadthread
 
bool cancelled = false
 

Member Function Documentation

◆ notifyOnSuccessCallback()

template<typename Value = void>
void aui::impl::future::Future< Value >::Inner::notifyOnSuccessCallback ( std::unique_lock< decltype(mutex)> & lock)
inlinenoexcept

Calls onSuccess callback.

Parameters
locklock of Inner::mutex mutex.

lock is expected to be locked. Under the lock, callback is moved to local stack, lock is unlocked, and only then callback is called. This helps to avoid deadlocks (i.e. retreiving AFuture's value in onSuccess callback). lock is not locked again. If AFuture does not have value or onSuccess callback, the lock remains untouched.

◆ tryExecute()

template<typename Value = void>
bool aui::impl::future::Future< Value >::Inner::tryExecute ( const _weak< CancellationWrapper< Inner > > & innerWeak)
inline

Executes the task stored in the future. Using weak_ptr to internal object in order to make possible Future cancellation by it's destruction.

Parameters
innerWeakself weak_ptr
Returns
true, then task is successfully executed and supplied result.

Member Data Documentation

◆ mutex

template<typename Value = void>
ASpinlockMutex aui::impl::future::Future< Value >::Inner::mutex

Spinlock mutex is used here because AFuture makes frequent calls to mutex and never locks for a long time. Durations are small enough so it is worth to just busy wait instead of making syscalls.

◆ value

template<typename Value = void>
std::conditional_t<isVoid, bool, AOptional<Value> > aui::impl::future::Future< Value >::Inner::value

When isVoid = true, bool is a flag whether "void value" supplied or not


The documentation for this struct was generated from the following file:
Collaboration diagram for aui::impl::future::Future< Value >::Inner: