AUI Framework
develop
Cross-platform base for C++ UI apps
|
Represents a value that will be available at some point in the future. More...
#include <AUI/Thread/AFuture.h>
T | result type (void is default) |
AFuture is returned by AUI_THREADPOOL keyword, which is used to perform heavy operations in a background thread.
If your operation consists of complex future sequences, you have multiple options:
operator*
and get()
methods (blocking value acquiring) within a threadpool thread (including the one that runs AUI_THREADPOOL 's body). If value is not currently available, these methods temporarily return the thread to threadpool, effeciently allowing it to execute other tasks. std::unique_lock
and similar RAII-based lock functions when performing blocking value acquiring operation.AFuture provides a set of functions for both "value emitting" side: supplyValue(), supplyException(), and "value receiving" side: operator->(), operator*(), get().
When AFuture's operation is completed it calls either onSuccess() or onError(). These callbacks are excepted to be called in any case. Use onFinally() to handle both.
AFuture is a shared_ptr-based wrapper so it can be easily copied, pointing to the same task.
If all AFutures of the task are destroyed, the task is cancelled. If the task is executing when cancel() is called, AFuture waits for the task, however, task's thread is still requested for interrupt. It guarantees that your task cannot be executed or be executing when AFuture destroyed and allows to efficiently utilize c++'s RAII feature.
To manage multiple AFutures, use AAsyncHolder or AFutureSet classes.
> All members, including inherited
|
inlinenoexcept |
The callback will be called on the worker's thread when the async task is returned a result.
onError does not expand AFuture's lifespan, so when AFuture becomes invalid, onSuccess would not be called.
|
inlinenoexcept |
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.
Contents