Crate rt
Expand description
The one async runtime model for Tilo processes.
Tokio is the only async runtime in Tilo. This crate decides how a process runs it, so that no app, daemon or CLI builds runtimes of its own:
- Apps share one current-thread runtime,
app(), on a dedicated background thread namedtilo-rt. It is never the UI or render thread. The UI spawns onto it and gets results back through the event loop’s existing wake mechanism (tilo_ui’sLatestRequest::spawnandLatestTask::spawnwrap that handoff); nothing on the UI thread waits on a future. - Daemons and services build one multi-thread runtime with
daemon(): a bounded worker count, a bounded blocking pool, named threads. - Synchronous entry points — a CLI’s
main, a test — useblock_on. It refuses to run inside a runtime or on the UI thread, where it would deadlock or freeze a frame. - CPU-bound bulk work — hashing, chunking, decoding, indexing — goes to
cpu(), a dedicated pool, never onto an async worker. - Bulk file I/O goes through
io, std I/O on dedicated threads behind an interface narrow enough to swap forio_uring. - Toolkit background work and timers go through
background, the executor a host installs, and wake the UI throughwake. - A long-lived thread of its own — an event loop, a device poller —
comes from
spawn_thread, neverstd::thread::spawn. - A pause inside async work — a retry backoff, a poll interval — is
sleep, neverstd::thread::sleep. - A helper a process can lose and restart runs inside
panic_boundary::isolate, so a process whose panic hook aborts for every other thread lets that one unwind (seepanic_boundary).
Every thread this crate starts is named, so a stack dump or top -H
attributes it.
In a browser (target_family = "wasm") no thread is started: app()
tasks run on the page thread from its microtask queue, cpu() work runs
there as an app task, io refuses, spawn_thread fails, and nothing
may block. availability answers which Features the running target
has, and each feature’s targets for every target.
Modules§
- background
- Background work and timers, provided by the host.
- io
- Bulk file I/O for async code, on dedicated threads.
- panic_
boundary - Which panics a process survives.
- wake
- Instance-scoped background wake routing shared by native and headless hosts.
Structs§
- AppRuntime
- The process-wide app runtime: a current-thread tokio runtime driven by a dedicated thread.
- CpuTask
- The pending result of
cpu(). Dropping it discards the result; work that has not started yet is skipped. - Daemon
- Builder for a service’s runtime. Start with
daemon(). - Handle
- Handle to the runtime.
- Join
Handle - An owned permission to join on a task (await its termination).
- Runtime
- The Tokio runtime.
Enums§
- Availability
- Whether a feature can be used on a target.
- Error
- Why a runtime operation was refused.
- Feature
- One capability of this crate, for
availability.
Functions§
- app
- The app runtime, started on first use.
- availability
- Whether
featurecan be used on this target. - available
- Whether
featurecan be used on this target without a prompt. - block_
on - Run
futureto completion on the calling thread. - cpu
- Run
workon thecpu_pooland await its result. - cpu_
pool - The process-wide CPU pool: one named thread (
tilo-cpu-N) per core. - daemon
- A multi-thread runtime for the service
name. - in_
async_ context - Whether the calling thread drives async tasks of a runtime from this
crate: a worker, the app runtime thread, or a thread inside one of its
block_ons. Blocking-pool threads do not count; they exist to block. - in_
runtime - Whether the calling thread is inside a tokio runtime context: a runtime
worker, the thread in a
block_on, a blocking-pool thread, or a thread that entered a handle. - is_
ui_ thread - Whether
mark_ui_threadwas called on this thread. - mark_
ui_ thread - Mark the calling thread as a UI (event-loop or render) thread.
- sleep
- Wait
duration, then resolve. Natively this is tokio’s timer, so it must run on a runtime with timers: the app runtime, a daemon orblock_on. In a page it is onesetTimeout, which a background tab may throttle. - sleep_
thread - Park the calling thread for
duration: the sanctioned replacement forstd::thread::sleep. Async code awaitssleepinstead. - spawn_
thread - Start a named OS thread: the sanctioned replacement for
std::thread::spawnandstd::thread::Builder::spawn. - try_app
- The app runtime, started on first use.