Move diffing job to worker thread instead of printing loop

The scoped thread API allows this change, and I think it's slightly easier
to follow. We can also remove the AtomicBool.
syntactic_context
Yuya Nishihara 2023-11-30 11:21:46 +07:00 committed by Wilfred Hughes
parent 44578368ab
commit d04a7cd78b
1 changed files with 10 additions and 13 deletions

@ -283,22 +283,19 @@ fn main() {
thread::scope(|s| {
let (send, recv) = std::sync::mpsc::sync_channel(1);
let encountered_changes = encountered_changes.clone();
let print_options = display_options.clone();
s.spawn(move || {
for diff_result in recv.into_iter() {
print_diff_result(&print_options, &diff_result);
if diff_result.has_reportable_change() {
encountered_changes.store(true, Ordering::Relaxed);
}
}
diff_iter
.try_for_each_with(send, |s, diff_result| s.send(diff_result))
.expect("Receiver should be connected")
});
diff_iter
.try_for_each_with(send, |s, diff_result| s.send(diff_result))
.expect("Receiver should be connected");
for diff_result in recv.into_iter() {
print_diff_result(&display_options, &diff_result);
if diff_result.has_reportable_change() {
encountered_changes.store(true, Ordering::Relaxed);
}
}
});
}
}