Shutdown the worker pool Prevents new jobs from being submitted and waits for all active jobs to complete.
(&self)
| 144 | /// |
| 145 | /// Prevents new jobs from being submitted and waits for all active jobs to complete. |
| 146 | pub async fn shutdown(&self) -> Result<Vec<Result<JobResult, JobError>>, JobError> { |
| 147 | // Mark as shutting down |
| 148 | *self.shutting_down.lock().await = true; |
| 149 | |
| 150 | // Wait for all active jobs to complete |
| 151 | let mut results = Vec::new(); |
| 152 | let mut jobs = self.active_jobs.lock().await; |
| 153 | |
| 154 | while let Some(result) = jobs.join_next().await { |
| 155 | match result { |
| 156 | Ok(job_result) => results.push(job_result), |
| 157 | Err(e) => results.push(Err(JobError::from(format!("Job panicked: {}", e)))), |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | Ok(results) |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | #[cfg(test)] |
no outgoing calls