Skip to content

Task API

Declared by <huxerui/task.h>.

Move-only, lazy coroutine return types. A task starts when launched or awaited. Only another HuxerUI task may co_await it. Exceptions are retained and rethrown on resume; a non-void task must co_return a value.

UseTaskScope() returns the current component’s scope. Launch(Task<void>&&) and the factory overload return TaskHandle. Outstanding executions are canceled when the owning scope is destroyed.

Copyable weak cancellation handle. Cancel() is safe after completion or prior cancellation.

Delay(std::chrono::duration<double>) -> Task<void> schedules resumption through the owning UI task system. Standard chrono duration literals are re-exported in huxerui.

#include <huxerui/huxerui.h>
using namespace huxerui;
Task<void> Refresh(State<std::string> status) {
status = "Loading";
co_await Delay(std::chrono::milliseconds(100));
status = "Ready";
}
View RefreshButton(State<std::string> status) {
auto tasks = UseTaskScope();
return Button("Refresh").OnClick([tasks, status] {
tasks.Launch(Refresh(status));
});
}

TaskScope owns launched work; destroying its component scope cancels outstanding executions before captured state can outlive that scope.