Skip to content

Commit 5927784

Browse files
committed
Add that_in_background
Closes #4
1 parent cb41dce commit 5927784

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/lib.rs

+9
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ use std::process::{Command, Stdio};
4646
use std::ffi::OsStr;
4747
use std::io;
4848
use std::process::ExitStatus;
49+
use std::thread;
4950

5051
#[cfg(not(any(target_os = "windows", target_os = "macos")))]
5152
pub fn that<T: AsRef<OsStr> + Sized>(path: T) -> io::Result<ExitStatus> {
@@ -107,6 +108,14 @@ pub fn that<T: AsRef<OsStr> + Sized>(path: T) -> io::Result<ExitStatus> {
107108
.wait()
108109
}
109110

111+
/// Convenience function for opening the passed path in a new thread.
112+
pub fn that_in_background<T: AsRef<OsStr> + Sized>(
113+
path: T,
114+
) -> thread::JoinHandle<io::Result<ExitStatus>> {
115+
let path = path.as_ref().to_os_string();
116+
thread::spawn(|| that(path))
117+
}
118+
110119
#[cfg(windows)]
111120
mod windows {
112121
use std::ffi::OsStr;

0 commit comments

Comments
 (0)