pub struct ShutdownController { /* private fields */ }Expand description
Controller for coordinated graceful shutdown.
This provides a clean way to propagate shutdown signals through an application. Multiple receivers can subscribe to receive shutdown notifications.
§Example
use asupersync::signal::ShutdownController;
async fn run_server() {
let controller = ShutdownController::new();
let mut receiver = controller.subscribe();
// Spawn a task that will receive the shutdown signal
let handle = async move {
receiver.wait().await;
println!("Shutting down...");
};
// Later, initiate shutdown
controller.shutdown();
}Implementations§
Source§impl ShutdownController
impl ShutdownController
Sourcepub fn new() -> ShutdownController
pub fn new() -> ShutdownController
Creates a new shutdown controller.
Sourcepub fn subscribe(&self) -> ShutdownReceiver
pub fn subscribe(&self) -> ShutdownReceiver
Gets a handle for receiving shutdown notifications.
Multiple receivers can be created and they will all be notified when shutdown is initiated.
Sourcepub fn shutdown(&self)
pub fn shutdown(&self)
Initiates shutdown.
This wakes all receivers that are currently waiting for shutdown. The shutdown state is persistent - once initiated, it cannot be reset.
Sourcepub fn is_shutting_down(&self) -> bool
pub fn is_shutting_down(&self) -> bool
Checks if shutdown has been initiated.
Sourcepub fn listen_for_signals(self: &Arc<ShutdownController>)
pub fn listen_for_signals(self: &Arc<ShutdownController>)
Spawns a background task to listen for shutdown signals.
This is a convenience method that sets up signal handling (when available) to automatically trigger shutdown.
§Note
In Phase 0, signal handling is not available, so this method only sets up the controller for manual shutdown calls.
Trait Implementations§
Source§impl Clone for ShutdownController
impl Clone for ShutdownController
Source§fn clone(&self) -> ShutdownController
fn clone(&self) -> ShutdownController
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more