mirror of
https://github.com/uutils/coreutils
synced 2024-11-16 01:38:04 +00:00
Merge pull request #937 from frewsxcv/refactor-timeout
Cleanup logic around `timeout` exit status handling.
This commit is contained in:
commit
6bae2688f3
1 changed files with 4 additions and 10 deletions
|
@ -116,21 +116,15 @@ impl ChildExt for Child {
|
|||
let mut exitstatus = lock.lock().unwrap();
|
||||
// Condvar::wait_timeout_ms() can wake too soon, in this case wait again
|
||||
let start = Instant::now();
|
||||
while exitstatus.is_none() {
|
||||
loop {
|
||||
if let Some(exitstatus) = exitstatus.take() {
|
||||
return exitstatus.map(Some);
|
||||
}
|
||||
if start.elapsed() >= timeout {
|
||||
return Ok(None)
|
||||
}
|
||||
let cvar_timeout = timeout - start.elapsed();
|
||||
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!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue