Skip to content

Commit

Permalink
Add that_in_background
Browse files Browse the repository at this point in the history
Closes #4
  • Loading branch information
heyimalex committed Aug 9, 2019
1 parent cb41dce commit 5927784
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ use std::process::{Command, Stdio};
use std::ffi::OsStr;
use std::io;
use std::process::ExitStatus;
use std::thread;

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

/// Convenience function for opening the passed path in a new thread.
pub fn that_in_background<T: AsRef<OsStr> + Sized>(
path: T,
) -> thread::JoinHandle<io::Result<ExitStatus>> {
let path = path.as_ref().to_os_string();
thread::spawn(|| that(path))
}

#[cfg(windows)]
mod windows {
use std::ffi::OsStr;
Expand Down

0 comments on commit 5927784

Please sign in to comment.