@@ -65,6 +65,7 @@ cfg_if! {
65
65
}
66
66
67
67
use std:: ops:: Add ;
68
+ use std:: panic:: { resume_unwind, catch_unwind, AssertUnwindSafe } ;
68
69
69
70
#[ derive( Debug ) ]
70
71
pub struct Atomic <T : Copy >( Cell <T >) ;
@@ -130,7 +131,19 @@ cfg_if! {
130
131
#[ macro_export]
131
132
macro_rules! parallel {
132
133
( $( $blocks: tt) , * ) => {
133
- $( $blocks) * ;
134
+ let mut panic = None ;
135
+ $(
136
+ if let Err ( p) = :: std:: panic:: catch_unwind(
137
+ :: std:: panic:: AssertUnwindSafe ( || $blocks)
138
+ ) {
139
+ if panic. is_none( ) {
140
+ panic = Some ( p) ;
141
+ }
142
+ }
143
+ ) *
144
+ if let Some ( panic) = panic {
145
+ :: std:: panic:: resume_unwind( panic) ;
146
+ }
134
147
}
135
148
}
136
149
@@ -140,6 +153,24 @@ cfg_if! {
140
153
t. into_iter( )
141
154
}
142
155
156
+ pub fn par_for_each_in<T : IntoIterator >(
157
+ t: T ,
158
+ for_each:
159
+ impl Fn ( <<T as IntoIterator >:: IntoIter as Iterator >:: Item ) + Sync + Send
160
+ ) {
161
+ let mut panic = None ;
162
+ t. into_iter( ) . for_each( |i| {
163
+ if let Err ( p) = catch_unwind( AssertUnwindSafe ( || for_each( i) ) ) {
164
+ if panic. is_none( ) {
165
+ panic = Some ( p) ;
166
+ }
167
+ }
168
+ } ) ;
169
+ if let Some ( panic) = panic {
170
+ resume_unwind( panic) ;
171
+ }
172
+ }
173
+
143
174
pub type MetadataRef = OwningRef <Box <dyn Erased >, [ u8 ] >;
144
175
145
176
pub use std:: rc:: Rc as Lrc ;
@@ -308,6 +339,15 @@ cfg_if! {
308
339
t. into_par_iter( )
309
340
}
310
341
342
+ pub fn par_for_each_in<T : IntoParallelIterator >(
343
+ t: T ,
344
+ for_each: impl Fn (
345
+ <<T as IntoParallelIterator >:: Iter as ParallelIterator >:: Item
346
+ ) + Sync + Send
347
+ ) {
348
+ t. into_par_iter( ) . for_each( for_each)
349
+ }
350
+
311
351
pub type MetadataRef = OwningRef <Box <dyn Erased + Send + Sync >, [ u8 ] >;
312
352
313
353
/// This makes locks panic if they are already held.
0 commit comments