Threading and Queues
Separate asynchronous transport from UI-owned state and server-owned GPU execution.
Hera uses separate execution contexts to let transport, UI evaluation, and device work progress without sharing all of their mutable state. Each boundary needs an explicit account of who owns the data, how delivery remains ordered, and how much pending work can accumulate.
Kit UI Thread Ownership
AppHost creates the application on a dedicated UI thread by running its view factory there. The resulting view, runtime, environment, layout system, and callbacks stay on that thread. This ownership allows models to contain Rc while avoiding the need to transfer them to asynchronous transport tasks.
The asynchronous host owns IPC progression and sends UiCommands through a bounded channel. The UI thread sends commit candidates and failures back through a separate bounded output channel.
Work Coalescing and Event Ordering
Before evaluating an update, UiLoop drains a bounded batch of commands, allowing several related state changes to coalesce into one candidate. Its needs_render and pending_commit state keeps that scheduling separate from publication: the model can continue changing while an outcome is pending, but the next nonempty candidate waits for a confirmed baseline.
Ordered server events enter the same UI queue. Commit confirmation must precede input that depends on the newly accepted geometry.
External Update Admission
AppHandle::update sends a Send + 'static mutation through a bounded queue. The UI applies it in a propagation batch, marks evaluation needed, and acknowledges execution.
The acknowledgment of an external update tells its caller that the mutation ran, while scene acceptance remains a later outcome. Cancelling the caller's wait cannot reverse an already admitted mutation. The callback must also return without waiting for work on the same UI thread, or it would block the queue needed to complete that work.
Asynchronous Wait Deadlines
The host limits asynchronous startup, writes, command delivery, and outcome waits. Those deadlines do not preempt an executing callback or guarantee a bounded thread join if user code never returns.
Shutdown releases channel directions before joining so a thread trying to send final output can observe closure. Transport closure must not wait for arbitrary user callback completion.
Rendering Device Ownership
The server gives device progression to a dedicated render worker, which also remains the sole reader of display events. The asynchronous frame driver can wait through PresentationSignal for readiness without consuming those events itself. This keeps identified activation and the resources it confirms under one owner.
The worker retains submitted snapshots and notifications until ownership is transferred safely. Cancellation must not lose scene history or free scanout resources prematurely.
See presentation and React Native runtime for the native host's separate event-loop design.
Source Reference
The following files in the Hera checkout define the behavior described on this page.
crates/kit/src/threading/mod.rscrates/kit/src/host/mod.rscrates/kit/src/host/updates.rscrates/renderer/src/worker/mod.rs