This will execute the `future` provided to completion and each invocation of `poll` for the future will be executed on a separate thread.
(future: F)
| 476 | /// This will execute the `future` provided to completion and each invocation of |
| 477 | /// `poll` for the future will be executed on a separate thread. |
| 478 | pub async fn execute_across_threads<F>(future: F) -> F::Output |
| 479 | where |
| 480 | F: Future + Send + 'static, |
| 481 | F::Output: Send, |
| 482 | { |
| 483 | let mut future = Box::pin(future); |
| 484 | loop { |
| 485 | let once = PollOnce::new(future); |
| 486 | let handle = tokio::runtime::Handle::current(); |
| 487 | let result = std::thread::spawn(move || handle.block_on(once)) |
| 488 | .join() |
| 489 | .unwrap(); |
| 490 | match result { |
| 491 | Ok(val) => break val, |
| 492 | Err(f) => future = f, |
| 493 | } |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | #[tokio::test] |
| 498 | #[cfg_attr(miri, ignore)] |
no test coverage detected