| 1 | #![cfg (feature = "rt" )] |
| 2 | #![cfg (not(target_os = "wasi" ))] // Wasi doesn't support threads |
| 3 | #![warn (rust_2018_idioms)] |
| 4 | |
| 5 | use tokio::runtime::Builder; |
| 6 | use tokio::time::*; |
| 7 | use tokio_util::context::RuntimeExt; |
| 8 | |
| 9 | #[test] |
| 10 | fn tokio_context_with_another_runtime() { |
| 11 | let rt1 = Builder::new_multi_thread() |
| 12 | .worker_threads(1) |
| 13 | // no timer! |
| 14 | .build() |
| 15 | .unwrap(); |
| 16 | let rt2 = Builder::new_multi_thread() |
| 17 | .worker_threads(1) |
| 18 | .enable_all() |
| 19 | .build() |
| 20 | .unwrap(); |
| 21 | |
| 22 | // Without the `HandleExt.wrap()` there would be a panic because there is |
| 23 | // no timer running, since it would be referencing runtime r1. |
| 24 | rt1.block_on(rt2.wrap(async move { sleep(Duration::from_millis(2)).await })); |
| 25 | } |
| 26 | |