Just call
start_kill(&mut self) from tokio Child
in Drop impl
struct ChildGuard(Child);
impl Drop for ChildGuard {
fn drop(&mut self) {
self.0.start_kill();
}
}
async fn my_async_process() {
let mut child = Command::new("sleep").arg("1").spawn().unwrap();
let mut child = SharedChild(child);
let _ = child.wait().await; // here you can kill by dropping future
}
async fn main() {
let fut = my_async_process();
// drop for example by `select!` or something else
drop(fut);
}
You can drop a
Future
from anotherFuture
in tokio so this is kinda solved.https://stackoverflow.com/questions/30538004/how-do-i-ensure-that-a-spawned-child-process-is-killed-if-my-app-panics
Just call
start_kill(&mut self)
from tokio Child in Drop impl