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