AUI_THREADPOOL#
Executes following {} block asynchronously in the global thread pool. Unlike
AUI_THREADPOOL_X, does now allow to set lambda's capture. Lambda's capture is [=].
| Header: | #include <AUI/Util/kAUI.h> |
| CMake: | aui_link(my_target PUBLIC aui::core) |
Definition#
#define AUI_THREADPOOL AThreadPool::global()* [=]()
Detailed Description#
When AFuture is destroyed, the corresponding AUI_THREADPOOL task is either cancelled or removed
from the execution queue. Use AFutureSet or AAsyncHolder to keep multiple AFuture
Example without a return value:
auto task = AUI_THREADPOOL {
AThread::sleep(1000); // a long task
};
Example with a return value:
auto futureStatus = AUI_THREADPOOL {
int status;
...
AThread::sleep(1000); // a long task
...
return status;
};
int status = *futureStatus;
Lambda operators are supported:
auto futureStatus = AUI_THREADPOOL mutable noexcept {
int status;
...
AThread::sleep(1000); // a long task
...
return status;
};
int status = *futureStatus;
Examples#
examples/ui/views/src/ExampleWindow.cpp
Views Example — All-in-one views building example.
AText::fromString("Building beautiful programs in pure C++ without chromium embedded framework") AUI_OVERRIDE_STYLE {
Expanding(1, 1),
},
Horizontal {} AUI_LET {
mAsync << AUI_THREADPOOL {
auto drawable = IDrawable::fromUrl(
"https://raster.shields.io/github/stars/aui-framework/aui?style=raster&logo=github");
AUI_UI_THREAD {
auto view = Icon { drawable } AUI_OVERRIDE_STYLE {
FixedSize { 80_dp, 20_dp },
examples/ui/infinite_lazy_list/src/main.cpp
Infinite Lazy List — Usage of AUI_DECLARATIVE_FOR to make an infinite lazy list.
if (!newState) { // we're interested in transitions to true state only.
return;
}
auto loadFrom = state->items->size(); // base index to load from.
state->asyncTasks << AUI_THREADPOOL {
// perform "loading" task on a worker thread.
AThread::sleep(500ms); // imitate hard work here
// aka "loaded" from backend storage of some kind