pub struct ShutdownController { /* private fields */ }Expand description
Owns the shutdown watch channel that fans one stop signal out to the serve loop and every cooperating background task. The receivers it hands out are cheap to clone.
Implementations§
Source§impl ShutdownController
impl ShutdownController
Sourcepub fn install() -> Self
pub fn install() -> Self
Spawn the OS-signal task and return a controller that is live
immediately. Requires an active Tokio runtime; the spawned task
translates the first shutdown_signal into a true on the channel.
Sourcepub fn manual() -> Self
pub fn manual() -> Self
Build a controller with no OS-signal task, triggered only through
ShutdownController::trigger. Useful for tests and for embeddings that
drive shutdown from their own signal source.
Sourcepub fn subscribe(&self) -> Receiver<bool>
pub fn subscribe(&self) -> Receiver<bool>
A receiver for a cooperating background loop. The canonical stop check is
while !*rx.borrow_and_update() { if rx.changed().await.is_err() { break } }.
Sourcepub fn trigger(&self)
pub fn trigger(&self)
Request a drain programmatically. This is the same path a signal takes, so an admin endpoint or a fatal-error handler can ask for the same clean teardown.
Sourcepub fn is_shutdown(&self) -> bool
pub fn is_shutdown(&self) -> bool
Whether a shutdown has already been requested.