Module background
Expand description
Background work and timers, provided by the host.
tilo_host::background and ui::background re-export this module.
Toolkit services that must not block a frame (image decoding, file-history
transport calls, periodic refreshes) hand their work to a Background
rather than spawning threads or sleeping themselves. The host decides how
that work runs:
ThreadPool— the default when no executor is entered: a bounded pool of named threads plus one timer thread, so native behaviour needs no setup;Pumped— a queue and a virtual clock that run only when their owner pumps them, for deterministic headless tests and for hosts that drive work from their own loop;PageExecutor— the default in a browser page, which has one thread: jobs run from the page’s microtask queue and timers aresetTimeouts;- any other
Executora host installs withBackground::enter.
Like crate::wake::WakeScope, the executor is captured when a service is
constructed: enter it around construction, and the service keeps using it
from any thread afterwards.
An executor may refuse work with Unsupported — a host with no threads
of its own, for example. Callers must degrade (report the feature as
unavailable, settle a request as failed) instead of retrying forever.
Structs§
- Background
- A cheap-to-clone handle to the executor a service was constructed under.
- Background
Guard - Restores the previously entered executor on drop. Thread-affine.
- NoBackground
- An executor that refuses all background work, for hosts that have none.
Timers still fire, on
park, so deadline-driven callers in a synchronous driver make progress. - Pumped
- An executor that runs nothing until its owner pumps it.
- Thread
Pool - A bounded pool of named worker threads, grown on demand, plus a single
timer thread for
Executor::wake_at. - Unsupported
- The host refused to run background work.
Traits§
- Executor
- How a host runs background work and timers.
Type Aliases§
- Job
- One unit of background work.