Expand description
§teksilo-async — optional main-thread async executor for Teksilo
Teksilo keeps the view layer synchronous: “async is the backend’s concern.”
Most background→UI flows are best served by the reactive data path
(ctx.subscribe_event(...) + Signal::set). This crate is the opt-in
escape hatch for the cases that want imperative async — writing linear
async / .await inside a handler, sequencing several awaits in one place.
ⓘ
use teksilo_async::{TeksiloAppBuilderAsyncExt, EventContextAsyncExt, spawn_blocking};
TeksiloAppBuilder::new().install_async() /* ... */ .run();
// inside a handler:
let status = self.status.clone(); // Signal<Status> (Rc clone)
ctx.spawn_local(async move {
status.set(Status::Loading);
let bytes = spawn_blocking(move || std::fs::read(path)).await;
status.set(Status::from(bytes)); // resume on the UI thread → set Signal
})
.detach();§Model
- The executor is single-threaded and
!Send;spawn_localfutures live on the UI thread and captureRc-basedSignals, mutating them on resume. There is noEventContextafter.await(it is borrow-transient), so UI updates flow through owned handles (Signals) — the reactive model. - For a one-shot ambient op after the work finishes (
open_window,send_intent, …),spawn_local_withdelivers the result to a callback with a freshEventContext. spawn_blockingoffloads blocking work to an OS thread and awaits the result — no async runtime required.
The executor is driven once per event-loop turn via the async-agnostic
on_loop_tick hook; it
sleeps (zero idle CPU) until a task is woken, including from a
spawn_blocking worker thread.
teksilo-tokio / teksilo-async-std build on this crate to add reactor
support so native-ecosystem futures (tokio::time, sockets, reqwest, …)
can be .awaited directly in UI code.
Structs§
- Async
Runtime Handle - Handle to the main-thread async runtime. Registered in app-state by
install_asyncand reached from a handler viactx.spawn_local(...)(EventContextAsyncExt).Cloneshares the same executor (Rc);!Send— it only ever lives on the UI thread. - Task
Handle - Handle to a spawned task. Dropping it cancels the task (the future is
dropped on the next tick); call
detachto let the task run to completion independently of the handle.
Enums§
- Blocking
Error - Why a
spawn_blockingfuture resolved to an error instead of a value.
Traits§
- Event
Context Async Ext - Spawn async work on the main-thread executor from inside an event handler.
- Teksilo
AppBuilder Async Ext - Adds
install_asyncto the app builder. Brought into scope withuse teksilo_async::TeksiloAppBuilderAsyncExt;(or via theteksiloprelude when theasyncfeature is on).
Functions§
- spawn_
blocking - Run
fon a dedicated OS thread and resolve to its return value. Await the returned future inside aspawn_localbody to keep heavy/blocking work off the UI thread: