Skip to main content

Crate teksilo_async

Crate teksilo_async 

Source
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_local futures live on the UI thread and capture Rc-based Signals, mutating them on resume. There is no EventContext after .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_with delivers the result to a callback with a fresh EventContext.
  • spawn_blocking offloads 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§

AsyncRuntimeHandle
Handle to the main-thread async runtime. Registered in app-state by install_async and reached from a handler via ctx.spawn_local(...) (EventContextAsyncExt). Clone shares the same executor (Rc); !Send — it only ever lives on the UI thread.
TaskHandle
Handle to a spawned task. Dropping it cancels the task (the future is dropped on the next tick); call detach to let the task run to completion independently of the handle.

Enums§

BlockingError
Why a spawn_blocking future resolved to an error instead of a value.

Traits§

EventContextAsyncExt
Spawn async work on the main-thread executor from inside an event handler.
TeksiloAppBuilderAsyncExt
Adds install_async to the app builder. Brought into scope with use teksilo_async::TeksiloAppBuilderAsyncExt; (or via the teksilo prelude when the async feature is on).

Functions§

spawn_blocking
Run f on a dedicated OS thread and resolve to its return value. Await the returned future inside a spawn_local body to keep heavy/blocking work off the UI thread: