pub struct System(/* private fields */);Expand description
Runtime manager for a group of arbiter threads.
A system stores runtime configuration, manages arbiters, dispatches process signals, and owns the blocking thread pool.
Clones share the same system and may be sent to other threads. Merely holding a handle does not install that system as the current system on another thread.
Implementations§
Source§impl System
impl System
Sourcepub fn build() -> Builder
pub fn build() -> Builder
Creates a builder for a system with a customized runtime.
See Builder for the available configuration options.
Sourcepub fn new<R: Runner>(name: &str, runner: R) -> SystemRunner
pub fn new<R: Runner>(name: &str, runner: R) -> SystemRunner
Creates a system runner with the specified name and runtime runner.
The system is not started until the returned runner is driven.
Sourcepub fn with_config(name: &str, config: SystemConfig) -> SystemRunner
pub fn with_config(name: &str, config: SystemConfig) -> SystemRunner
Creates a system runner from an existing configuration.
Replaces the configuration’s name with name. Signal and panic handling
are disabled for the new runner. The system starts only when it is driven.
Sourcepub fn current() -> System
pub fn current() -> System
Returns the system running on the current thread.
§Panics
Panics if no system is running on the current thread.
Sourcepub fn try_current() -> Option<System>
pub fn try_current() -> Option<System>
Returns the system running on the current thread, if one exists.
Sourcepub fn stop(&self)
pub fn stop(&self)
Requests that the system stop with exit code 0.
This does not wait for shutdown. See stop_with_code.
Sourcepub fn stop_with_code(&self, code: i32)
pub fn stop_with_code(&self, code: i32)
Requests that the system stop with the specified exit code.
The request is processed asynchronously on the primary arbiter, which
asks all registered arbiters to stop. SystemRunner::run reports
nonzero codes as errors. A runner awaiting a user future with
SystemRunner::block_on still waits for that future to complete.
Sourcepub fn enable_signals(&self)
pub fn enable_signals(&self)
Enables process signal handling.
Signals are handled by one system at a time, this has no effect while another system handles signals. Call this on the system’s primary arbiter thread, where its signal-delivery task and shutdown state live.
Sourcepub fn disable_signals(&self)
pub fn disable_signals(&self)
Disables process signal handling.
Sourcepub fn list_arbiters<F, R>(&self, f: F) -> R
pub fn list_arbiters<F, R>(&self, f: F) -> R
Provides access to all arbiters registered with this system.
The callback receives a snapshot, including the primary arbiter while it remains registered. It runs without the registry lock held, so it may create, stop, join, or enumerate arbiters. This method may be called from any thread.
Sourcepub fn list_arbiter_pings<F>(f: F)
pub fn list_arbiter_pings<F>(f: F)
Visits the latest ping records for each registered arbiter.
This method should be called from the thread where the system has been initialized, typically the “main” thread, because records are thread-local. Records are stored newest first, with at most ten per arbiter before callbacks modify them. Arbiters without records are not visited.
The callback may modify the stored records and runs without the arbiter registry lock, but must not call this method recursively.
§Panics
Panics if no current system is installed or if called recursively.
Sourcepub fn spawn_blocking<F, R>(&self, f: F) -> BlockingResult<R> ⓘ
pub fn spawn_blocking<F, R>(&self, f: F) -> BlockingResult<R> ⓘ
Submits blocking work to this system’s thread pool and returns its result future.
This method does not wait for completion. It may be called from any thread, regardless of which system is current there.
Dropping the returned future prevents queued work from starting, but
cannot interrupt work that is already running. Call
BlockingResult::detach to let queued work continue even if its
result is no longer needed.
Sourcepub fn pool_metrics(&self) -> PoolMetrics
pub fn pool_metrics(&self) -> PoolMetrics
Returns a snapshot of the blocking thread pool metrics.
Sourcepub fn get_value<T>(&self, f: impl FnOnce() -> T) -> T
pub fn get_value<T>(&self, f: impl FnOnce() -> T) -> T
Returns a clone of the system-wide value of type T, inserting one if absent.
This method acquires a lock on the internal data structure.
To avoid repeated locking, prefer storing a cloned value in the arbiter’s storage.
Initialization is not atomic: concurrent callers may each run f and
return different values, with the last inserted clone remaining in storage.