diff options
| author | mo8it <mo8it@proton.me> | 2024-09-06 15:40:25 +0200 |
|---|---|---|
| committer | mo8it <mo8it@proton.me> | 2024-09-06 15:40:25 +0200 |
| commit | 2d26358602fc1cd0a026f634b38c34e7b4618cc9 (patch) | |
| tree | 423b6efab39073fcf8d4021374fa87c15c2a0f01 /src/app_state.rs | |
| parent | 9faa5d3aa48f7a94ed87e61ad6ea659579f1311a (diff) | |
Use the thread builder and handle the spawn error
Diffstat (limited to 'src/app_state.rs')
| -rw-r--r-- | src/app_state.rs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/app_state.rs b/src/app_state.rs index ed723c2..ecb4689 100644 --- a/src/app_state.rs +++ b/src/app_state.rs @@ -388,13 +388,20 @@ impl AppState { let handles = self .exercises .iter() - .map(|exercise| s.spawn(|| exercise.run_exercise(None, &self.cmd_runner))) + .map(|exercise| { + thread::Builder::new() + .spawn_scoped(s, || exercise.run_exercise(None, &self.cmd_runner)) + }) .collect::<Vec<_>>(); - for (exercise_ind, handle) in handles.into_iter().enumerate() { + for (exercise_ind, spawn_res) in handles.into_iter().enumerate() { write!(stdout, "\rProgress: {exercise_ind}/{n_exercises}")?; stdout.flush()?; + let Ok(handle) = spawn_res else { + return Ok(AllExercisesCheck::CheckedUntil(exercise_ind)); + }; + let Ok(success) = handle.join().unwrap() else { return Ok(AllExercisesCheck::CheckedUntil(exercise_ind)); }; |
