()
| 1 | use tokio::task; |
| 2 | |
| 3 | pub async fn run() { |
| 4 | let task_a = task::spawn(fetch_data_async( |
| 5 | "https://jsonplaceholder.typicode.com/posts/1", |
| 6 | )); |
| 7 | let task_b = task::spawn(fetch_data_async( |
| 8 | "https://jsonplaceholder.typicode.com/posts/2", |
| 9 | )); |
| 10 | let task_c = task::spawn(fetch_data_async( |
| 11 | "https://jsonplaceholder.typicode.com/posts/3", |
| 12 | )); |
| 13 | |
| 14 | let (res_a, res_b, res_c) = tokio::join!(task_a, task_b, task_c); |
| 15 | |
| 16 | match (res_a, res_b, res_c) { |
| 17 | (Ok(a), Ok(b), Ok(c)) => { |
| 18 | println!("{:?}", a); |
| 19 | println!("{:?}", b); |
| 20 | println!("{:?}", c); |
| 21 | } |
| 22 | _ => println!("Failed to fetch data"), |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | async fn fetch_data_async(url: &str) -> Result<String, reqwest::Error> { |
| 27 | let response = reqwest::get(url).await?; |
nothing calls this directly
no test coverage detected