| 218 | } |
| 219 | |
| 220 | pub fn dispatch_async<A, R, F, E>( |
| 221 | atoms: Vec<A>, |
| 222 | cfg: HpcParallelConfig, |
| 223 | callback: F, |
| 224 | ) -> AsyncParallelHandle<R> |
| 225 | where |
| 226 | A: Send + Sync + 'static, |
| 227 | R: Send + 'static, |
| 228 | F: Fn(&[A]) -> Result<R, E> + Send + Sync + 'static, |
| 229 | E: Display + Send + 'static, |
| 230 | { |
| 231 | let (tx, rx) = mpsc::channel(); |
| 232 | let join_handle = thread::spawn(move || { |
| 233 | let report = run_parallel(&atoms, cfg, callback); |
| 234 | let _ = tx.send(report); |
| 235 | }); |
| 236 | AsyncParallelHandle { join_handle, result_rx: rx } |
| 237 | } |
| 238 | |
| 239 | fn run_serial<A, R, F, E>( |
| 240 | atoms: &[A], |