refactor(cli): move thread pool setup to command execution, use thread::spawn instead of rayon::spawn in the logger thread

This commit is contained in:
ttyS3 2024-12-02 12:49:19 +00:00 committed by João Marcos
parent 6b38e1dd46
commit 77b01d170f
3 changed files with 10 additions and 8 deletions

View File

@ -28,13 +28,6 @@ impl CliArgs {
set_accessible(args.accessible);
if let Some(threads) = args.threads {
rayon::ThreadPoolBuilder::new()
.num_threads(threads)
.build_global()
.unwrap();
}
let (Subcommand::Compress { files, .. }
| Subcommand::Decompress { files, .. }
| Subcommand::List { archives: files, .. }) = &mut args.cmd;

View File

@ -53,6 +53,14 @@ pub fn run(
question_policy: QuestionPolicy,
file_visibility_policy: FileVisibilityPolicy,
) -> crate::Result<()> {
if let Some(threads) = args.threads {
rayon::ThreadPoolBuilder::new()
.num_threads(threads)
.build_global()
.unwrap();
}
match args.cmd {
Subcommand::Compress {
files,

View File

@ -1,4 +1,5 @@
use std::sync::{mpsc, Arc, Barrier, OnceLock};
use std::thread;
pub use logger_thread::spawn_logger_thread;
@ -168,7 +169,7 @@ mod logger_thread {
pub fn spawn_logger_thread() {
let log_receiver = setup_channel();
rayon::spawn(move || run_logger(log_receiver));
thread::spawn(move || run_logger(log_receiver));
}
fn run_logger(log_receiver: LogReceiver) {