@@ -2,6 +2,7 @@ use std::{
2
2
future:: Future ,
3
3
marker:: PhantomData ,
4
4
mem,
5
+ panic:: AssertUnwindSafe ,
5
6
sync:: Arc ,
6
7
thread:: { self , JoinHandle } ,
7
8
} ;
@@ -300,19 +301,54 @@ impl TaskPool {
300
301
301
302
let tick_task_pool_executor = tick_task_pool_executor || self . threads . is_empty ( ) ;
302
303
if let Some ( thread_ticker) = thread_executor. ticker ( ) {
303
- let tick_forever = async move {
304
- loop {
305
- thread_ticker. tick ( ) . await ;
306
- }
307
- } ;
308
-
309
304
if tick_task_pool_executor {
310
- executor. run ( tick_forever) . or ( get_results) . await
305
+ let execute_forever = async move {
306
+ // we restart the executors if a task errors. if a scoped
307
+ // task errors it will panic the scope on the call to get_results
308
+ loop {
309
+ let tick_forever = async {
310
+ loop {
311
+ thread_ticker. tick ( ) . await ;
312
+ }
313
+ } ;
314
+
315
+ // we don't care if it errors. If a scoped task errors it will propagate
316
+ // to get_results
317
+ let _result = AssertUnwindSafe ( executor. run ( tick_forever) )
318
+ . catch_unwind ( )
319
+ . await
320
+ . is_ok ( ) ;
321
+ }
322
+ } ;
323
+ execute_forever. or ( get_results) . await
311
324
} else {
312
- tick_forever. or ( get_results) . await
325
+ let execute_forever = async {
326
+ loop {
327
+ let tick_forever = async {
328
+ loop {
329
+ thread_ticker. tick ( ) . await ;
330
+ }
331
+ } ;
332
+
333
+ let _result =
334
+ AssertUnwindSafe ( tick_forever) . catch_unwind ( ) . await . is_ok ( ) ;
335
+ }
336
+ } ;
337
+
338
+ execute_forever. or ( get_results) . await
313
339
}
314
340
} else if tick_task_pool_executor {
315
- executor. run ( get_results) . await
341
+ let execute_forever = async {
342
+ loop {
343
+ let _result =
344
+ AssertUnwindSafe ( executor. run ( std:: future:: pending :: < ( ) > ( ) ) )
345
+ . catch_unwind ( )
346
+ . await
347
+ . is_ok ( ) ;
348
+ }
349
+ } ;
350
+
351
+ execute_forever. or ( get_results) . await
316
352
} else {
317
353
get_results. await
318
354
}
0 commit comments