Skip to main content

Crate tilo_rt

Crate tilo_rt 

Source
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.
JoinHandle
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_thread runs, as a Linux nice value.

Traits§

MaybeSend
Send where the platform has threads; nothing on the web.

Functions§

app
availability
available
block_on
Run future to 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 calls par_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 through cpu_pool, which is sized per core on purpose.
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; 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 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_background_thread
spawn_thread for 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 runs BACKGROUND_NICE steps 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::spawn and std::thread::Builder::spawn.
spawn_worker
Run body on 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 future on runtime and wait for its output on the calling thread.