use std::time::Duration;
use super::Process;
use crate::error::Error;
impl Process {
pub async fn graceful_shutdown(&self, grace: Duration) -> Result<(), Error> {
crate::wait::terminate(self.id())?;
let watch = crate::tokio::wait::grace_wait(self.id(), grace).await;
if matches!(watch, Ok(true)) {
return Ok(()); }
if let Err(ref e) = watch {
log::debug!("graceful_shutdown watch error before kill escalation (subsumed): {e}");
}
crate::wait::kill(self.id())?;
watch?;
Ok(())
}
pub async fn graceful_shutdown_tree(&self, grace: Duration) -> Result<(), Error> {
self.terminate_tree()?; let watch = crate::tokio::wait::grace_wait(self.id(), grace).await;
if let Err(ref e) = watch {
log::debug!("graceful_shutdown_tree watch error before kill_tree sweep (may be subsumed): {e}");
}
self.kill_tree()?;
watch?;
Ok(())
}
}
#[cfg(test)]
#[path = "graceful_tests.rs"]
mod graceful_tests;