From cef0f384829de4f4ccea0edf5fb0c6d26b30616e Mon Sep 17 00:00:00 2001 From: Quaternions Date: Thu, 11 Jan 2024 22:07:01 -0800 Subject: [PATCH] pray rayon doesn't spawn 600 threads and crash --- src/main.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9c5ab7d..8cfa66b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -648,17 +648,17 @@ async fn write_files(config:WriteConfig,mut context:DecompiledContext)->AResult< } //run the async - std::thread::scope(|s|{ - let threads:Vec>>=write_queue.into_iter().map(|(write_path,node,node_name_override)| - s.spawn(||write_item(&context.dom,write_path,node,node_name_override,config.write_models,config.write_scripts)) - ).collect(); - for thread in threads{ - match thread.join(){ - Ok(_)=>(), - Err(e)=>println!("thread error: {:?}",e), - } + { + let dom=&context.dom; + let write_models=config.write_models; + let write_scripts=config.write_scripts; + let results:Vec>=rayon::iter::ParallelIterator::collect(rayon::iter::ParallelIterator::map(rayon::iter::IntoParallelIterator::into_par_iter(write_queue),|(write_path,node,node_name_override)|{ + write_item(&dom,write_path,node,node_name_override,write_models,write_scripts) + })); + for result in results{ + result?; } - }); + } //run the destroy for destroy_ref in destroy_queue{