1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-05 07:27:46 +00:00

Cleanup logic around wait_or_timeout exit status handling.

This commit is contained in:
Corey Farwell 2016-08-04 20:02:55 -04:00 committed by Roy Ivy III
parent 72d2ab208c
commit c6909951aa

View file

@ -116,21 +116,15 @@ impl ChildExt for Child {
let mut exitstatus = lock.lock().unwrap(); let mut exitstatus = lock.lock().unwrap();
// Condvar::wait_timeout_ms() can wake too soon, in this case wait again // Condvar::wait_timeout_ms() can wake too soon, in this case wait again
let start = Instant::now(); let start = Instant::now();
while exitstatus.is_none() { loop {
if let Some(exitstatus) = exitstatus.take() {
return exitstatus.map(Some);
}
if start.elapsed() >= timeout { if start.elapsed() >= timeout {
return Ok(None) return Ok(None)
} }
let cvar_timeout = timeout - start.elapsed(); let cvar_timeout = timeout - start.elapsed();
exitstatus = cvar.wait_timeout(exitstatus, cvar_timeout).unwrap().0; exitstatus = cvar.wait_timeout(exitstatus, cvar_timeout).unwrap().0;
} }
// Turn Option<Result<ExitStatus>> into Result<Option<ExitStatus>>
match exitstatus.take() {
Some(r) => match r {
Ok(s) => Ok(Some(s)),
Err(e) => Err(e),
},
None => panic!(),
}
} }
} }