gix_filter/driver/
shutdown.rs

1use bstr::BString;
2
3use crate::driver::State;
4
5///
6#[derive(Debug, Copy, Clone)]
7pub enum Mode {
8    /// Wait for long-running processes after signaling them to shut down by closing their input and output.
9    WaitForProcesses,
10    /// Do not do anything with long-running processes, which typically allows them to keep running or shut down on their own time.
11    /// This is the fastest mode as no synchronization happens at all.
12    Ignore,
13}
14
15/// Lifecycle
16impl State {
17    /// Handle long-running processes according to `mode`. If an error occurs, all remaining processes will be ignored automatically.
18    /// Return a list of `(process, Option<status>)`
19    pub fn shutdown(self, mode: Mode) -> Result<Vec<(BString, Option<std::process::ExitStatus>)>, std::io::Error> {
20        let mut out = Vec::with_capacity(self.running.len());
21        for (cmd, client) in self.running {
22            match mode {
23                Mode::WaitForProcesses => {
24                    let mut child = client.into_child();
25                    let status = child.wait()?;
26                    out.push((cmd, Some(status)));
27                }
28                Mode::Ignore => {
29                    out.push((cmd, None));
30                }
31            }
32        }
33        Ok(out)
34    }
35}