Skip to main content

systemd_transient/
handle.rs

1use std::time::Duration;
2
3use crate::{SystemdTransientManager, UnitExit, error::SystemdTransientError};
4
5pub struct TransientUnitHandle {
6  pub(crate) name: String,
7  pub(crate) stop_timeout: Duration,
8  pub(crate) manager: SystemdTransientManager,
9}
10
11impl TransientUnitHandle {
12  pub async fn stop(self) -> Result<(), SystemdTransientError> {
13    self.manager.stop(&self.name, self.stop_timeout).await?;
14    // TODO: should we assert that the unit was actuallty stopped and not failed already before?
15    // TODO: is waiting for the job the same as wait_for_exit?
16    //self.manager.wait_for_exit(&self.name).await?;
17    Ok(())
18  }
19
20  pub async fn wait_for_exit(&self) -> Result<UnitExit, SystemdTransientError> {
21    self.manager.wait_for_exit(&self.name).await
22  }
23}