From 5927784721174259af5e6f3d07f724f5b6e89501 Mon Sep 17 00:00:00 2001 From: Alex Guerra Date: Fri, 9 Aug 2019 14:44:30 -0500 Subject: [PATCH] Add that_in_background Closes #4 --- src/lib.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index ad039b3..7fa8c97 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 + Sized>(path: T) -> io::Result { @@ -107,6 +108,14 @@ pub fn that + Sized>(path: T) -> io::Result { .wait() } +/// Convenience function for opening the passed path in a new thread. +pub fn that_in_background + Sized>( + path: T, +) -> thread::JoinHandle> { + let path = path.as_ref().to_os_string(); + thread::spawn(|| that(path)) +} + #[cfg(windows)] mod windows { use std::ffi::OsStr;