Task API
Declared by <huxerui/task.h>.
Task<T> and Task<void>
Section titled “Task<T> and Task<void>”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.
TaskScope
Section titled “TaskScope”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.
TaskHandle
Section titled “TaskHandle”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.
Complete scoped-task example
Section titled “Complete scoped-task example”#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.

