(
waker: Waker,
title: &str,
kind: Job,
run: impl FnOnce(JobContext, Receiver<()>) -> Result<JobResult> + Send + 'static,
)
| 171 | } |
| 172 | |
| 173 | fn start_job( |
| 174 | waker: Waker, |
| 175 | title: &str, |
| 176 | kind: Job, |
| 177 | run: impl FnOnce(JobContext, Receiver<()>) -> Result<JobResult> + Send + 'static, |
| 178 | ) -> JobState { |
| 179 | let status = Arc::new(RwLock::new(JobStatus { |
| 180 | title: title.to_string(), |
| 181 | progress_percent: 0.0, |
| 182 | progress_items: None, |
| 183 | status: String::new(), |
| 184 | error: None, |
| 185 | })); |
| 186 | let context = JobContext { status: status.clone(), waker: waker.clone() }; |
| 187 | let context_inner = JobContext { status: status.clone(), waker }; |
| 188 | let (tx, rx) = std::sync::mpsc::channel(); |
| 189 | let handle = std::thread::spawn(move || match run(context_inner, rx) { |
| 190 | Ok(state) => state, |
| 191 | Err(e) => { |
| 192 | if let Ok(mut w) = status.write() { |
| 193 | w.error = Some(e); |
| 194 | } |
| 195 | JobResult::None |
| 196 | } |
| 197 | }); |
| 198 | let id = JOB_ID.fetch_add(1, Ordering::Relaxed); |
| 199 | JobState { id, kind, handle: Some(handle), context, cancel: tx } |
| 200 | } |
| 201 | |
| 202 | fn update_status( |
| 203 | context: &JobContext, |
no test coverage detected