Expand description
The one async runtime model for Tilo processes.
Tokio is the only async runtime in Tilo, and this crate decides how a process runs it,
so no app, daemon or CLI builds runtimes of its own: app() for an app’s one
current-thread runtime, daemon() for a bounded multi-thread one, block_on for a
synchronous entry point, cpu() and io for bulk work off the async workers,
background for the host’s executor and timers, spawn_thread for a thread of its
own and sleep for a pause. Every thread this crate starts is named.
In a browser no thread is started: app() tasks run on the page’s microtask queue,
and nothing may block. availability answers which Features the target has.
Re-exports§
pub use tilo_wake as wake;
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.
- stall
- What a process was doing when it stalled.
Structs§
- AppRuntime
- The process-wide app runtime: a current-thread tokio runtime driven by a dedicated thread.
- CpuTask
- 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
- Error
- Why a runtime operation was refused.
- Feature
Constants§
- BACKGROUND_
NICE - How far below an ordinary thread
spawn_background_threadruns, as a Linux nice value.
Traits§
- Maybe
Send Sendwhere the platform has threads; nothing on the web.
Functions§
- app
- availability
- available
- block_
on - Run
futureto completion on the calling thread. - bound_
parallel_ pool - Build rayon’s process-wide pool before a library builds it, so its size is
[
LIBRARY_THREADS] rather than one worker per logical CPU: a library that first callspar_iter(a message layer’s group tree, a renderer, a text layout) builds that pool itself, and on a machine with hundreds of CPUs it then holds hundreds of idle threads for work that is a handful of items. Bulk work a person waits for goes throughcpu_pool, which is sized per core on purpose. - 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; their thread exists to block, though they are inside a runtime all the same (in_runtime). - 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 - lower_
current_ thread_ priority - Lower the calling thread (only it: Linux keeps a nice value per thread)
to
BACKGROUND_NICE. Failure leaves it as it was, which is only slower. - mark_
ui_ thread - off_
ui_ thread - Mark a call that waits — on the session, the device, a service — and so may take seconds. A debug build panics when it runs on a window’s thread: the window would stop drawing and answering for as long as it waits, so a test or a development build that reaches it there fails instead.
- 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_
background_ thread spawn_threadfor work a person does not wait on frame by frame — rasterising pages ahead of a scroll, decoding, indexing — that must never take a CPU from the thread drawing the window. On Linux the thread runsBACKGROUND_NICEsteps below its spawner, so on a machine with one or two slow cores the UI thread is scheduled first and the work fills the time it leaves; elsewhere it is an ordinary thread.- spawn_
thread - Start a named OS thread: the sanctioned replacement for
std::thread::spawnandstd::thread::Builder::spawn. - spawn_
worker - Run
bodyon a worker thread where the target has them, and inline where it has none (a browser page). A caller that owns one long-lived loop for its own work keeps one shape on every target without selecting by target itself. - thread_
cpu_ time - timer_
now - The instant the runtime’s timers measure against: tokio’s clock, which a test runtime started paused holds still and advances itself. A deadline that a tokio timer enforces is read on this clock, so the timer and the expiry check agree however promptly a loaded host runs them.
- try_app
- wait_on
- Run
futureonruntimeand wait for its output on the calling thread.