From f95a268167acec4b831134369ac51cf322078660 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 15 Feb 2018 00:08:07 -0800 Subject: [PATCH] Simplify the parallel Result with collect() --- src/lib.rs | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 49ea740..171d4b7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -905,23 +905,11 @@ impl Build { } } - let results: Mutex>> = Mutex::new(Vec::new()); - - objs.par_iter().with_max_len(1).for_each( - |obj| { - let res = self.compile_object(obj); - results.lock().unwrap().push(res) - }, - ); - // Check for any errors and return the first one found. - for result in results.into_inner().unwrap().iter() { - if result.is_err() { - return result.clone(); - } - } - - Ok(()) + objs.par_iter() + .with_max_len(1) + .map(|obj| self.compile_object(obj)) + .collect() } #[cfg(not(feature = "parallel"))]