AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
AFuture< void > Class Referencefinal

Public Types

using Task = typename super::TaskCallback
 
using Inner = decltype(std::declval< super >().inner())
 
- Public Types inherited from aui::impl::future::Future< void >
using TaskCallback = std::function< void()>
 
using OnSuccessCallback = typename OnSuccessCallback< void >::type
 

Public Member Functions

 AFuture (Task task=nullptr) noexcept
 
 AFuture (const AFuture &)=default
 
 AFuture (AFuture &&) noexcept=default
 
AFutureoperator= (const AFuture &)=default
 
AFutureoperator= (AFuture &&) noexcept=default
 
void supplyException (std::exception_ptr causedBy=std::current_exception()) const noexcept
 Stores an exception from std::current_exception to the future.
 
void supplyValue () const noexcept
 Pushes "success" result. More...
 
AFutureoperator= (std::nullptr_t) noexcept
 
bool operator== (const AFuture &r) const noexcept
 
template<aui::invocable Callback>
const AFutureonSuccess (Callback &&callback) const
 Add onSuccess callback to the future. More...
 
template<aui::invocable< const AException & > Callback>
const AFutureonError (Callback &&callback) const
 Add onSuccess callback to the future. More...
 
template<aui::invocable Callback>
const AFutureonFinally (Callback &&callback) const
 Adds the callback to both onSuccess and onResult.
 
- Public Member Functions inherited from aui::impl::future::Future< void >
 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
 
void onSuccess (Callback &&callback) const
 
void onError (Callback &&callback) const
 
void onFinally (Callback &&callback) const
 Adds the callback to both onSuccess and onResult.
 
void cancel () const noexcept
 Cancels the AFuture's task. More...
 
void reportInterrupted () const
 
void wait (AFutureWait flags=AFutureWait::DEFAULT) const
 Sleeps if the supplyValue is not currently available. More...
 
FutureReturnType< void >::type get (AFutureWait flags=AFutureWait::DEFAULT) const
 Returns the supplyValue from the another thread. Sleeps if the supplyValue is not currently available. More...
 
FutureReturnType< void >::type operator* () const
 Returns the task result from the another thread. Sleeps if the task result is not currently available. More...
 
FutureReturnType< void >::type operator* ()
 Returns the supplyValue from the another thread. Sleeps if the supplyValue is not currently available. More...
 
void * operator-> () const
 Returns the supplyValue from the another thread. Sleeps if the supplyValue is not currently available. More...
 

Additional Inherited Members

- Static Public Attributes inherited from aui::impl::future::Future< void >
static constexpr bool isVoid
 
- Protected Attributes inherited from aui::impl::future::Future< void >
_< CancellationWrapper< Inner > > mInner
 

Member Function Documentation

◆ onError()

template<aui::invocable< const AException & > Callback>
const AFuture & AFuture< void >::onError ( Callback &&  callback) const
inline

Add onSuccess callback to the future.

The callback will be called on the worker's thread when the async task is returned a result.

onSuccess does not expand AFuture's lifespan, so when AFuture becomes invalid, onSuccess would not be called.

Note
To expand lifespan, create an AAsyncHolder inside your window or object; then put the instance of AFuture there. Example:
...
private:
AAsyncHolder mAsync;
...
mAsync << functionReturningFuture().onSuccess(...); // or onError
Holds a set of futures keeping them valid.
Definition: AAsyncHolder.h:30

◆ onSuccess()

template<aui::invocable Callback>
const AFuture & AFuture< void >::onSuccess ( Callback &&  callback) const
inline

Add onSuccess callback to the future.

The callback will be called on the worker's thread when the async task is returned a result.

onSuccess does not expand AFuture's lifespan, so when AFuture becomes invalid, onSuccess would not be called.

Note
To expand lifespan, create an AAsyncHolder inside your window or object; then put the instance of AFuture there. Example:
...
private:
AAsyncHolder mAsync;
...
mAsync << functionReturningFuture().onSuccess(...); // or onError

◆ supplyValue()

void AFuture< void >::supplyValue ( ) const
inlinenoexcept

Pushes "success" result.

supplyValue calls onSuccess listeners with the new value.


The documentation for this class was generated from the following file:
Inheritance diagram for AFuture< void >:
Collaboration diagram for AFuture< void >: