use tokio::{
io,
process::{Child, ChildStderr, ChildStdout},
};
use super::{CrocEventStream, Result};
pub struct CrocChild {
inner: Child,
}
impl CrocChild {
pub fn new(inner: Child) -> Self {
Self { inner }
}
pub fn take_stderr(&mut self) -> Option<ChildStderr> {
self.inner.stderr.take()
}
pub fn take_stdout(&mut self) -> Option<ChildStdout> {
self.inner.stdout.take()
}
pub fn events(&mut self) -> Result<CrocEventStream> {
CrocEventStream::new(self)
}
pub async fn kill(&mut self) -> io::Result<()> {
self.inner.kill().await
}
pub fn try_kill(&mut self) -> io::Result<()> {
let exited = self.inner.try_wait()?;
if exited.is_none() {
self.inner.start_kill()?;
}
Ok(())
}
pub fn id(&self) -> Option<u32> {
self.inner.id()
}
}
impl std::fmt::Debug for CrocChild {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.inner.fmt(f)
}
}