| 16 | |
| 17 | #[async_std::main] |
| 18 | async fn main() { |
| 19 | a().await; |
| 20 | b().await; |
| 21 | println!("serial\n"); |
| 22 | |
| 23 | let result = a().join(b()).await; |
| 24 | println!("joined\n"); |
| 25 | assert_eq!(result, (1u8, 2u8)); |
| 26 | |
| 27 | let result = a().race(b()).await; // often called `select` |
| 28 | println!("raced {:?}\n", result); |
| 29 | |
| 30 | // `BoxedExt::boxed()` does `Box::pin(a()) as Pin<Box<dyn Future<Output = Foo>>>` for us |
| 31 | let futures: Vec<_> = vec![b().boxed(), a().boxed(), b().boxed()]; |
| 32 | assert_eq!(join_all(futures).await, [2, 1, 2]); |
| 33 | println!("joined vector\n"); |
| 34 | } |