diff --git a/src/process.rs b/src/process.rs index c16b97ebd..4ff35738b 100644 --- a/src/process.rs +++ b/src/process.rs @@ -844,9 +844,9 @@ impl Child { /// guaranteed to repeatedly return a successful exit status so long as the /// child has already exited. /// - /// If the child has exited, then `Ok(status)` is returned. If the exit - /// status is not available at this time then an error is returned with the - /// error kind `WouldBlock`. If an error occurs, then that error is returned. + /// If the child has exited, then `Ok(Some(status))` is returned. If the + /// exit status is not available at this time then `Ok(None)` is returned. + /// If an error occurs, then that error is returned. /// /// Note that unlike `wait`, this function will not attempt to drop stdin. /// @@ -857,14 +857,13 @@ impl Child { /// ```no_run /// #![feature(process_try_wait)] /// - /// use std::io; /// use std::process::Command; /// /// let mut child = Command::new("ls").spawn().unwrap(); /// /// match child.try_wait() { - /// Ok(status) => println!("exited with: {}", status), - /// Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => { + /// Ok(Some(status)) => println!("exited with: {}", status), + /// Ok(None) => { /// println!("status not ready yet, let's really wait"); /// let res = child.wait(); /// println!("result: {:?}", res); @@ -873,8 +872,8 @@ impl Child { /// } /// ``` #[unstable(feature = "process_try_wait", issue = "38903")] - pub fn try_wait(&mut self) -> io::Result { - self.handle.try_wait().map(ExitStatus) + pub fn try_wait(&mut self) -> io::Result> { + Ok(self.handle.try_wait()?.map(ExitStatus)) } /// Simultaneously waits for the child to exit and collect all remaining diff --git a/src/sys/redox/process.rs b/src/sys/redox/process.rs index 50dcd44b4..60dc03fcf 100644 --- a/src/sys/redox/process.rs +++ b/src/sys/redox/process.rs @@ -502,17 +502,17 @@ impl Process { Ok(ExitStatus(status as i32)) } - pub fn try_wait(&mut self) -> io::Result { + pub fn try_wait(&mut self) -> io::Result> { if let Some(status) = self.status { - return Ok(status) + return Ok(Some(status)) } let mut status = 0; let pid = cvt(syscall::waitpid(self.pid, &mut status, syscall::WNOHANG))?; if pid == 0 { - Err(io::Error::from_raw_os_error(syscall::EWOULDBLOCK)) + Ok(None) } else { self.status = Some(ExitStatus(status as i32)); - Ok(ExitStatus(status as i32)) + Ok(Some(ExitStatus(status as i32))) } } } diff --git a/src/sys/unix/process/process_fuchsia.rs b/src/sys/unix/process/process_fuchsia.rs index 87acb0ed9..0bb2e0c1a 100644 --- a/src/sys/unix/process/process_fuchsia.rs +++ b/src/sys/unix/process/process_fuchsia.rs @@ -165,7 +165,7 @@ impl Process { Ok(ExitStatus::new(proc_info.rec.return_code)) } - pub fn try_wait(&mut self) -> io::Result { + pub fn try_wait(&mut self) -> io::Result> { use default::Default; use sys::process::magenta::*; @@ -179,7 +179,7 @@ impl Process { match status { 0 => { }, // Success x if x == ERR_TIMED_OUT => { - return Err(io::Error::from(io::ErrorKind::WouldBlock)); + return Ok(None); }, _ => { panic!("Failed to wait on process handle: {}", status); }, } @@ -192,7 +192,7 @@ impl Process { return Err(io::Error::new(io::ErrorKind::InvalidData, "Failed to get exit status of process")); } - Ok(ExitStatus::new(proc_info.rec.return_code)) + Ok(Some(ExitStatus::new(proc_info.rec.return_code))) } } diff --git a/src/sys/unix/process/process_unix.rs b/src/sys/unix/process/process_unix.rs index 0dc1739c1..bbc987209 100644 --- a/src/sys/unix/process/process_unix.rs +++ b/src/sys/unix/process/process_unix.rs @@ -249,19 +249,19 @@ impl Process { Ok(ExitStatus::new(status)) } - pub fn try_wait(&mut self) -> io::Result { + pub fn try_wait(&mut self) -> io::Result> { if let Some(status) = self.status { - return Ok(status) + return Ok(Some(status)) } let mut status = 0 as c_int; let pid = cvt(unsafe { libc::waitpid(self.pid, &mut status, libc::WNOHANG) })?; if pid == 0 { - Err(io::Error::from_raw_os_error(libc::EWOULDBLOCK)) + Ok(None) } else { self.status = Some(ExitStatus::new(status)); - Ok(ExitStatus::new(status)) + Ok(Some(ExitStatus::new(status))) } } } diff --git a/src/sys/windows/process.rs b/src/sys/windows/process.rs index d2ad81023..1afb3728c 100644 --- a/src/sys/windows/process.rs +++ b/src/sys/windows/process.rs @@ -340,18 +340,18 @@ impl Process { } } - pub fn try_wait(&mut self) -> io::Result { + pub fn try_wait(&mut self) -> io::Result> { unsafe { match c::WaitForSingleObject(self.handle.raw(), 0) { c::WAIT_OBJECT_0 => {} c::WAIT_TIMEOUT => { - return Err(io::Error::from_raw_os_error(c::WSAEWOULDBLOCK)) + return Ok(None); } _ => return Err(io::Error::last_os_error()), } let mut status = 0; cvt(c::GetExitCodeProcess(self.handle.raw(), &mut status))?; - Ok(ExitStatus(status)) + Ok(Some(ExitStatus(status))) } }