ASharedRaiiHelper#
Shared completion marker for multithreaded callback-based future handling.
Header: | #include <AUI/Util/ASharedRaiiHelper.h> |
CMake: | aui_link(my_target PUBLIC aui::core) |
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;