pub struct ShutdownHandler { /* private fields */ }Expand description
Coordinates graceful shutdown with signal handling and interruptible sleep.
Thread-safe and cloneable via ShutdownToken.
Implementations§
Source§impl ShutdownHandler
impl ShutdownHandler
Sourcepub fn with_signal_handlers() -> Self
pub fn with_signal_handlers() -> Self
Create a new ShutdownHandler that installs signal handlers: SIGINT
(Ctrl+C), SIGTERM and SIGHUP on Unix; every console control event
(Ctrl+C, Ctrl+Break, closing the console) on Windows. SIGTERM is what
docker stop and systemd send; as PID 1 in a container an uncaught
SIGTERM is ignored and the process ends in SIGKILL without running any
hook.
Sourcepub fn trigger_delayed(&self, delay: Duration)
pub fn trigger_delayed(&self, delay: Duration)
Trigger shutdown after a delay. The delay runs in a background thread.
Sourcepub fn is_shutdown(&self) -> bool
pub fn is_shutdown(&self) -> bool
Returns true once shutdown has been triggered.
Sourcepub fn wait_timeout(&self, timeout: Duration) -> bool
pub fn wait_timeout(&self, timeout: Duration) -> bool
Block until shutdown or timeout. Returns true if shutdown was triggered.
Sourcepub fn sleep(&self, duration: Duration) -> bool
pub fn sleep(&self, duration: Duration) -> bool
Interruptible sleep. Returns true if interrupted by shutdown.
Sourcepub fn register_hook<F: FnOnce() + Send + 'static>(&self, hook: F)
pub fn register_hook<F: FnOnce() + Send + 'static>(&self, hook: F)
Register a cleanup hook. Called exactly once when shutdown is triggered. If shutdown has already occurred, the hook is called immediately.
Sourcepub fn token(&self) -> ShutdownToken
pub fn token(&self) -> ShutdownToken
Get a cheaply cloneable token that shares shutdown state.
Sourcepub fn reset_for_testing(&self)
pub fn reset_for_testing(&self)
Reset for testing purposes only. Clears the shutdown flag and re-enables hooks.
Trait Implementations§
Source§impl Clone for ShutdownHandler
impl Clone for ShutdownHandler
Source§fn clone(&self) -> ShutdownHandler
fn clone(&self) -> ShutdownHandler
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more