Skip to main content

Crate teksilo_tokio

Crate teksilo_tokio 

Source
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§

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.
TokioHandle
Shared background Tokio runtime, registered in app-state by install_async_tokio. Fetch with ctx.app_state::<TokioHandle>() to spawn Send tasks on the background runtime or obtain a tokio::runtime::Handle. Clone shares the same runtime (Arc).

Traits§

EventContextAsyncExt
Spawn async work on the main-thread executor from inside an event handler.
TeksiloAppBuilderTokioExt
Adds install_async_tokio to the app builder.

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: