Skip to content

Commit

Permalink
Simplify helper join logic
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 committed May 13, 2019
1 parent 9b738c6 commit 5a395f0
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -970,9 +970,8 @@ mod imp {
use std::io;
use std::sync::{Arc, Mutex};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::{self, SyncSender, Receiver, RecvTimeoutError};
use std::thread::{self, Builder, JoinHandle};
use std::time::Duration;
use std::sync::mpsc::{self, SyncSender, Receiver};
use std::thread::{Builder, JoinHandle};
use std::process::Command;

#[derive(Debug)]
Expand Down Expand Up @@ -1063,22 +1062,8 @@ mod imp {
impl Helper {
pub fn join(self) {
self.quitting.store(true, Ordering::SeqCst);
let dur = Duration::from_millis(10);
let mut done = false;
for _ in 0..100 {
match self.rx_done.recv_timeout(dur) {
Ok(()) |
Err(RecvTimeoutError::Disconnected) => {
done = true;
break
}
Err(RecvTimeoutError::Timeout) => {}
}
thread::yield_now();
}
if done {
drop(self.thread.join());
}
let _ = self.rx_done.recv();
drop(self.thread.join());
}
}
}

0 comments on commit 5a395f0

Please sign in to comment.