use super::Child;
use crate::error::Error;
use crate::identity::ProcessId;
use crate::tokio::Command;
#[cfg(windows)]
#[path = "suspended/windows.rs"]
mod platform;
#[cfg(not(windows))]
#[path = "suspended/unsupported.rs"]
mod platform;
#[derive(Debug)]
pub struct SuspendedChild {
child: Child,
wanted_kill_on_drop: bool,
}
impl Command {
pub fn spawn_suspended(&mut self) -> Result<SuspendedChild, Error> {
platform::spawn(self)
}
}
impl SuspendedChild {
pub fn id(&self) -> ProcessId {
self.child.id()
}
pub fn resume(self) -> Result<Child, Error> {
let SuspendedChild {
mut child,
wanted_kill_on_drop,
} = self;
match platform::release(&child) {
Ok(()) => {
child.kill_on_drop = wanted_kill_on_drop;
child.commit_kill_on_drop();
Ok(child)
}
Err(e) => {
let fate = child.tear_down_now();
Err(crate::child::spawn::after_the_spawn(
Error::Containment {
detail: format!("could not resume the frozen child: {e}"),
},
fate,
child.behind_wrapper(),
))
}
}
}
}
#[cfg(test)]
#[path = "suspended_tests.rs"]
mod suspended_tests;