Expand description
§teksilo-tokio — Tokio reactor for Teksilo’s async executor
Thin adapter over teksilo-async: it installs the same
main-thread executor, but wraps each executor tick in a
tokio::runtime::Runtime context so native Tokio futures (timers,
sockets, reqwest, sqlx, …) can be .awaited directly inside
ctx.spawn_local(...) bodies.
ⓘ
use teksilo_tokio::TeksiloAppBuilderTokioExt;
TeksiloAppBuilder::new().install_async_tokio() /* ... */ .run();
// inside a handler:
ctx.spawn_local(async move {
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
let body = reqwest::get(url).await?.text().await?;
status.set(body); // resume on the UI thread → set a Signal
})
.detach();§How it works
The executor polls !Send futures on the UI thread. A multi-thread Tokio
runtime runs the reactor / timer driver on background threads. By entering
the runtime context (runtime.enter()) around each tick, a Tokio leaf
future polled on the UI thread registers with that background driver — and
crucially registers our executor’s Waker. When the timer/socket is
ready, the background driver wakes our Waker, which nudges the event loop
to tick again. No blocking, no second event loop.
Structs§
- 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. - Tokio
Handle - Shared background Tokio runtime, registered in app-state by
install_async_tokio. Fetch withctx.app_state::<TokioHandle>()to spawnSendtasks on the background runtime or obtain atokio::runtime::Handle.Cloneshares the same runtime (Arc).
Traits§
- Event
Context Async Ext - Spawn async work on the main-thread executor from inside an event handler.
- Teksilo
AppBuilder Tokio Ext - Adds
install_async_tokioto the app builder.
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: