pub struct ShutdownCoordinator { /* private fields */ }Expand description
Shutdown coordinator
Manages graceful shutdown with grace period and timeout enforcement.
Implementations§
Source§impl ShutdownCoordinator
impl ShutdownCoordinator
Sourcepub fn new(grace_period: Duration) -> Self
pub fn new(grace_period: Duration) -> Self
Create a new shutdown coordinator
§Arguments
grace_period- Maximum time to wait for graceful shutdown
Sourcepub fn token(&self) -> CancellationToken
pub fn token(&self) -> CancellationToken
Get a cancellation token
Tokens can be cloned and passed to async tasks for shutdown signaling.
Sourcepub fn is_shutting_down(&self) -> bool
pub fn is_shutting_down(&self) -> bool
Check if shutdown has been initiated
Sourcepub fn initiate_shutdown(&self)
pub fn initiate_shutdown(&self)
Initiate graceful shutdown
This will:
- Set shutdown initiated flag
- Cancel all tokens
- Start grace period timer
Sourcepub async fn wait_for_shutdown(&self) -> bool
pub async fn wait_for_shutdown(&self) -> bool
Wait for shutdown to complete or timeout
Returns true if shutdown completed within grace period,
false if timeout occurred.
§Examples
use adaptive_pipeline_bootstrap::shutdown::ShutdownCoordinator;
use std::time::Duration;
let coordinator = ShutdownCoordinator::new(Duration::from_secs(5));
// In main application loop
coordinator.initiate_shutdown();
// Wait for all tasks to complete
if coordinator.wait_for_shutdown().await {
println!("Shutdown completed gracefully");
} else {
println!("Shutdown timed out, forcing exit");
}
coordinator.complete_shutdown();Sourcepub fn complete_shutdown(&self)
pub fn complete_shutdown(&self)
Signal that shutdown is complete
Call this after all cleanup is done to notify waiters.
Sourcepub async fn wait_with_timeout(&self, timeout: Duration) -> bool
pub async fn wait_with_timeout(&self, timeout: Duration) -> bool
Wait for shutdown with custom timeout
Trait Implementations§
Source§impl Clone for ShutdownCoordinator
impl Clone for ShutdownCoordinator
Source§fn clone(&self) -> ShutdownCoordinator
fn clone(&self) -> ShutdownCoordinator
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for ShutdownCoordinator
impl RefUnwindSafe for ShutdownCoordinator
impl Send for ShutdownCoordinator
impl Sync for ShutdownCoordinator
impl Unpin for ShutdownCoordinator
impl UnwindSafe for ShutdownCoordinator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more