Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
portals::UiAsync Class Reference

Optional UI owner of at most one coroutine frame and one wait, with no separate runtime. Uses one permanent node-scope registration and at most one timer/data registration. Existing Scheduler capacities and dispatch budgets apply. Tree and scheduler must outlive this owner. Destruction is UI-only, does not join workers, and defers a currently executing frame's release until resume returns. No method requests redraw; coroutine application effects invalidate explicitly. More...

#include <async.hpp>

Public Member Functions

 ~UiAsync ()
 Close on UI; foreign-thread destruction terminates.
 UiAsync (const UiAsync &)=delete
UiAsync & operator= (const UiAsync &)=delete
UiAsyncContext context () const
std::expected< void, AsyncError > start (UiTask &&task, UiTaskRestart restart=UiTaskRestart::REJECT_RUNNING)
 Adopt and initially resume on UI; subsequent waits resume through scheduler dispatch.
std::expected< void, AsyncError > cancel ()
 Cancel on UI; suspended frame is released now, executing frame after resume returns.
std::expected< void, AsyncError > close ()
 Permanently close on UI without joining; idempotent.
std::expected< UiTaskOutcome, AsyncError > outcome () const

Static Public Member Functions

static std::expected< std::unique_ptr< UiAsync >, AsyncError > create (Scheduler &scheduler, WidgetTree &tree, Node< Widget > context)

Friends

struct ui::detail::AsyncAccess

Detailed Description

Optional UI owner of at most one coroutine frame and one wait, with no separate runtime. Uses one permanent node-scope registration and at most one timer/data registration. Existing Scheduler capacities and dispatch budgets apply. Tree and scheduler must outlive this owner. Destruction is UI-only, does not join workers, and defers a currently executing frame's release until resume returns. No method requests redraw; coroutine application effects invalidate explicitly.

Member Function Documentation

◆ cancel()

std::expected< void, AsyncError > portals::UiAsync::cancel ( )

Cancel on UI; suspended frame is released now, executing frame after resume returns.

Returns
Success including idle/completed owners, or WRONG_THREAD. Outcome remains inspectable.

◆ close()

std::expected< void, AsyncError > portals::UiAsync::close ( )

Permanently close on UI without joining; idempotent.

Returns
Success or WRONG_THREAD; outcome remains readable after closure/removal.

◆ context()

UiAsyncContext portals::UiAsync::context ( ) const
Returns
Weak context for owning parameters of a free/static coroutine function; foreign access returns an empty context without reading mutable UI state.

◆ create()

std::expected< std::unique_ptr< UiAsync >, AsyncError > portals::UiAsync::create ( Scheduler & scheduler,
WidgetTree & tree,
Node< Widget > context )
static
Parameters
schedulerExisting UI scheduler; must own the node scope and outlive this owner.
treeExisting UI tree; must outlive the owner.
contextLive node whose removal cancels the frame and closes this owner.
Returns
UI owner, or typed context/thread/frame/registration/allocation failure.

◆ outcome()

std::expected< UiTaskOutcome, AsyncError > portals::UiAsync::outcome ( ) const
Returns
Retained invocation outcome, including after node removal; WRONG_THREAD on foreign access.

◆ start()

std::expected< void, AsyncError > portals::UiAsync::start ( UiTask && task,
UiTaskRestart restart = UiTaskRestart::REJECT_RUNNING )

Adopt and initially resume on UI; subsequent waits resume through scheduler dispatch.

Parameters
taskLazy task created on this UI thread; consumed only on successful adoption.
restartExplicit repeated-action policy, defaulting to preserving running work.
Returns
Admission success, or typed rejection. Self-close/removal during first resume returns CLOSED; business success/failure is separately retained by outcome(). Rejection before adoption preserves task; first-resume failure has consumed it.

The documentation for this class was generated from the following file: