pub struct SystemRunner { /* private fields */ }Expand description
Runner that keeps a System’s event loop alive until stop message is received.
Implementations§
Source§impl SystemRunner
impl SystemRunner
Sourcepub fn run_with_code(self) -> Result<i32>
pub fn run_with_code(self) -> Result<i32>
Runs the event loop until stopped, returning the exit code.
Sourcepub fn runtime(&self) -> &Runtime
pub fn runtime(&self) -> &Runtime
Retrieves a reference to the underlying Actix runtime associated with this
SystemRunner instance.
The Actix runtime is responsible for managing the event loop for an Actix system and executing asynchronous tasks. This method provides access to the runtime, allowing direct interaction with its features.
In a typical use case, you might need to share the same runtime between different
parts of your project. For example, some components might require a Runtime to spawn
tasks on the same runtime.
Read more in the documentation for Runtime.
§Examples
let system_runner = actix_rt::System::new();
let actix_runtime = system_runner.runtime();
// Use the runtime to spawn an async task or perform other operations§Note
While this method provides an immutable reference to the Actix runtime, which is safe to share across threads, be aware that spawning blocking tasks on the Actix runtime could potentially impact system performance. This is because the Actix runtime is responsible for driving the system, and blocking tasks could delay other tasks in the run loop.
Sourcepub fn stop_future(&self) -> SystemStop ⓘ
pub fn stop_future(&self) -> SystemStop ⓘ
Returns a future that resolves with the system’s exit code when it is stopped.
This can be used to react to a system stop signal while running a future with
SystemRunner::block_on, such as when coordinating shutdown with tokio::select!.
§Examples
use std::process::ExitCode;
use actix_rt::System;
let sys = System::new();
let stop = sys.stop_future();
let exit = sys.block_on(async move {
actix_rt::spawn(async {
System::current().stop_with_code(0);
});
let code = stop.await.unwrap_or(1);
ExitCode::from(code as u8)
});
Sourcepub fn into_parts(self) -> (Runtime, SystemStop)
pub fn into_parts(self) -> (Runtime, SystemStop)
Splits this runner into its runtime and a future that resolves when the system stops.
After calling this method, SystemRunner::run and SystemRunner::run_with_code can no
longer be used.