refactor: centralize thread spawning for item writing

This commit is contained in:
Andrew Phillips (aider)
2025-05-12 11:13:06 -03:00
parent f3f3c6d628
commit d31ab6e793

View File

@@ -141,33 +141,34 @@ pub fn mode_diff(
log::debug!("THREAD: Done sending item to diff");
}
// Thread to write Item A data to diff
let writer_thread_a = {
let pipe_writer_a_raw = unsafe { std::fs::File::from_raw_fd(fd_a_write) };
let item_path_a_clone = item_path_a.clone();
let compression_type_a_clone = compression_type_a.clone();
// Function to spawn a writer thread for an item
fn spawn_writer_thread(
item_path: PathBuf,
compression_type: CompressionType,
fd_write: nix::unistd::Fd,
) -> std::thread::JoinHandle<()> {
let pipe_writer_raw = unsafe { std::fs::File::from_raw_fd(fd_write) };
std::thread::spawn(move || {
write_item_to_pipe(
item_path_a_clone,
compression_type_a_clone,
pipe_writer_a_raw,
item_path,
compression_type,
pipe_writer_raw,
);
})
};
}
// Thread to write Item B data to diff
let writer_thread_b = {
let pipe_writer_b_raw = unsafe { std::fs::File::from_raw_fd(fd_b_write) };
let item_path_b_clone = item_path_b.clone();
let compression_type_b_clone = compression_type_b.clone();
std::thread::spawn(move || {
write_item_to_pipe(
item_path_b_clone,
compression_type_b_clone,
pipe_writer_b_raw,
// Spawn writer threads for both items
let writer_thread_a = spawn_writer_thread(
item_path_a.clone(),
compression_type_a.clone(),
fd_a_write,
);
let writer_thread_b = spawn_writer_thread(
item_path_b.clone(),
compression_type_b.clone(),
fd_b_write,
);
})
};
// Thread to read diff's standard output
let stdout_reader_thread = std::thread::spawn(move || {