AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
ASharedRaiiHelper Class Reference

Shared completion marker for multithreaded callback-based future handling. More...

#include <AUI/Util/ASharedRaiiHelper.h>

Detailed Description

ASharedRaiiHelper is intended to track the completion of multiple futures, exploiting the destruction of AFuture::onSuccess or AFuture::onError callbacks when they called. This approach allows to easily integrate ASharedRaiiHelper to the existing code.

Note that the callback will be called even if onSuccess is not.

auto marker = ASharedRaiiHelper::make([] {
    // will be called when all futures called onSuccess or destroyed
});
auto future = AUI_THREADPOOL {
    // hard work
}
//                      VVVVVV ASharedRaiiHelper should be captured!
future.onSuccess([this, marker]() {
    // handle the hard work
});
// keep the future alive in AUI_THREADPOOL holder
mAsyncHolder << future;
#define AUI_THREADPOOL
Executes following {} block asynchronously in the global thread pool. Unlike AUI_THREADPOOL_X,...
Definition kAUI.h:329