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

Classes

struct  Inner
 

Public Types

using TaskCallback = std::function<Value()>
 
using OnSuccessCallback = typename OnSuccessCallback<Value>::type
 

Public Member Functions

 Future (TaskCallback task=nullptr)
 
const _< CancellationWrapper< Inner > > & inner () const noexcept
 
bool isWaitNeeded () const noexcept
 
bool hasResult () const noexcept
 
bool hasValue () const noexcept
 
void reportException () const noexcept
 
template<typename Callback>
void onSuccess (Callback &&callback) const
 
template<aui::invocable< const AException & > Callback>
void onError (Callback &&callback) const
 
template<aui::invocable Callback>
void onFinally (Callback &&callback) const
 Adds the callback to both onSuccess and onResult.
 
void cancel () const noexcept
 Cancels the AFuture's task.
 
void reportInterrupted () const
 
void wait (AFutureWait flags=AFutureWait::DEFAULT) const
 Sleeps if the supplyValue is not currently available.
 
FutureReturnType< Value >::type get (AFutureWait flags=AFutureWait::DEFAULT) const
 Returns the supplyValue from the another thread. Sleeps if the supplyValue is not currently available.
 
FutureReturnType< Value >::type operator* () const
 Returns the task result from the another thread. Sleeps if the task result is not currently available.
 
FutureReturnType< Value >::type operator* ()
 Returns the supplyValue from the another thread. Sleeps if the supplyValue is not currently available.
 
Value * operator-> () const
 Returns the supplyValue from the another thread. Sleeps if the supplyValue is not currently available.
 

Static Public Attributes

static constexpr bool isVoid = std::is_same_v<void, Value>
 

Protected Attributes

_< CancellationWrapper< Inner > > mInner
 

Constructor & Destructor Documentation

◆ Future()

template<typename Value = void>
aui::impl::future::Future< Value >::Future ( TaskCallback task = nullptr)
inline
Parameters
taska callback which will be executed by Future::Inner::tryExecute. Can be null. If null, the result should be provided by AFuture::supplyValue function.

Member Function Documentation

◆ cancel()

template<typename Value = void>
void aui::impl::future::Future< Value >::cancel ( ) const
inlinenoexcept

Cancels the AFuture's task.

When cancel() is called, there are 3 possible cases:

  1. AFuture's task is not taken by AThreadPool. The task is simply removed from the AThreadPool queue.
  2. AFuture's task is being executed. The task's thread is requested for interrupt.
  3. AFuture's task is already completed. cancel() does nothing.

◆ get()

template<typename Value = void>
FutureReturnType< Value >::type aui::impl::future::Future< Value >::get ( AFutureWait flags = AFutureWait::DEFAULT) const
inline

Returns the supplyValue from the another thread. Sleeps if the supplyValue is not currently available.

Sneaky exceptions
AInvoсationTargetException thrown if invocation target has thrown an exception.
Returns
the object stored from the another thread.

◆ hasResult()

template<typename Value = void>
bool aui::impl::future::Future< Value >::hasResult ( ) const
inlinenodiscardnoexcept
Returns
true if the value or exception or interruption was received.

◆ hasValue()

template<typename Value = void>
bool aui::impl::future::Future< Value >::hasValue ( ) const
inlinenodiscardnoexcept
Returns
true if asynchronous operation was successfuly completed and supplied a value, which can be obtained without waiting.

◆ isWaitNeeded()

template<typename Value = void>
bool aui::impl::future::Future< Value >::isWaitNeeded ( ) const
inlinenodiscardnoexcept
Returns
true if call to wait() function would cause thread block.

◆ operator*() [1/2]

template<typename Value = void>
FutureReturnType< Value >::type aui::impl::future::Future< Value >::operator* ( )
inline

Returns the supplyValue from the another thread. Sleeps if the supplyValue is not currently available.

Sneaky exceptions
AInvoсationTargetException thrown if invocation target has thrown an exception.
Returns
the object stored from the another thread.

◆ operator*() [2/2]

template<typename Value = void>
FutureReturnType< Value >::type aui::impl::future::Future< Value >::operator* ( ) const
inline

Returns the task result from the another thread. Sleeps if the task result is not currently available.

Sneaky exceptions
AInvoсationTargetException thrown if invocation target has thrown an exception.
Returns
the object stored from the another thread.

◆ operator->()

template<typename Value = void>
Value * aui::impl::future::Future< Value >::operator-> ( ) const
inline

Returns the supplyValue from the another thread. Sleeps if the supplyValue is not currently available.

Sneaky exceptions
AInvoсationTargetException thrown if invocation target has thrown an exception.
Returns
the object stored from the another thread.

◆ wait()

template<typename Value = void>
void aui::impl::future::Future< Value >::wait ( AFutureWait flags = AFutureWait::DEFAULT) const
inline

Sleeps if the supplyValue is not currently available.

Note
The task will be executed inside wait() function if the threadpool have not taken the task to execute yet. This behaviour can be disabled by AFutureWait::JUST_WAIT flag.

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