Skip to main content

Crate rt

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 named tilo-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’s LatestRequest::spawn and LatestTask::spawn wrap 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 — use block_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 for io_uring.
  • Toolkit background work and timers go through background, the executor a host installs, and wake the UI through wake.
  • A long-lived thread of its own — an event loop, a device poller — comes from spawn_thread, never std::thread::spawn.
  • A pause inside async work — a retry backoff, a poll interval — is sleep, never std::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 (see panic_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.
JoinHandle
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 feature can be used on this target.
available
Whether feature can be used on this target without a prompt.
block_on
Run future to completion on the calling thread.
cpu
Run work on the cpu_pool and 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_thread was 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 or block_on. In a page it is one setTimeout, which a background tab may throttle.
sleep_thread
Park the calling thread for duration: the sanctioned replacement for std::thread::sleep. Async code awaits sleep instead.
spawn_thread
Start a named OS thread: the sanctioned replacement for std::thread::spawn and std::thread::Builder::spawn.
try_app
The app runtime, started on first use.