(&mut self, dur: Duration, mut closure: impl FnMut() + Send + 'static)
| 1031 | |
| 1032 | impl HelperThread { |
| 1033 | fn run_periodically(&mut self, dur: Duration, mut closure: impl FnMut() + Send + 'static) { |
| 1034 | let state = self.state.clone(); |
| 1035 | self.thread = Some(std::thread::spawn(move || { |
| 1036 | // Using our mutex/condvar we wait here for the first of `dur` to |
| 1037 | // pass or the `HelperThread` instance to get dropped. |
| 1038 | let mut should_exit = state.should_exit.lock().unwrap(); |
| 1039 | while !*should_exit { |
| 1040 | let (lock, result) = state |
| 1041 | .should_exit_cvar |
| 1042 | .wait_timeout(should_exit, dur) |
| 1043 | .unwrap(); |
| 1044 | should_exit = lock; |
| 1045 | // If we timed out for sure then there's no need to continue |
| 1046 | // since we'll just abort on the next `checked_sub` anyway. |
| 1047 | if result.timed_out() { |
| 1048 | closure(); |
| 1049 | } |
| 1050 | } |
| 1051 | })); |
| 1052 | } |
| 1053 | } |
| 1054 | |
| 1055 | impl Drop for HelperThread { |
no test coverage detected