use super::{Child, SuspendedChild};
use crate::child::spawn::spawn_uncommitted;
use crate::child::suspended::platform::{refusal, spawn_frozen};
use crate::containment::windows::{resume_initial_threads, SuspendCount};
use crate::error::Error;
use crate::tokio::child::async_policy;
use crate::tokio::spawn::{on_pool, spawn_failure};
use crate::tokio::Command;
impl SuspendedChild {
#[doc(hidden)]
pub fn test_job_handle_contains_self(&self) -> bool {
self.child.test_job_handle_contains_self()
}
#[doc(hidden)]
pub fn test_job_kills_on_close(&self) -> bool {
self.child.inner.tree.job_kills_on_close_for_test()
}
#[doc(hidden)]
pub fn test_containment(&self) -> crate::Containment {
self.child.containment()
}
}
pub(super) async fn spawn(cmd: &mut Command) -> Result<SuspendedChild, Error> {
if let Some(refusal) = refusal(cmd.as_sync_mut()) {
return Err(refusal);
}
let policy = async_policy();
let (child, wanted_kill_on_drop) = on_pool(
cmd.as_sync_mut(),
"cosca::tokio::Command::spawn_suspended",
move |cmd| spawn_frozen(cmd, |cmd| spawn_uncommitted(cmd, policy, crate::identity::HostKernel)),
)
.await
.map_err(spawn_failure)??;
Ok(SuspendedChild {
child: Child::from_sync(child),
wanted_kill_on_drop,
})
}
pub(super) fn release(child: &Child) -> std::io::Result<()> {
resume_initial_threads(child.inner.process_handle(), SuspendCount::ExactlyOne)
}