#[tokio::main]
async fn main() {
let urls = vec!["https://example.com", "https://rust-lang.org"];
let futures = urls.into_iter().map(|url| fetch_data(url));
let results: Vec<_> = futures::future::join_all(futures).await;
for result in results {
match result {
Ok(data) => println!("Fetched data: {}", data),
Err(e) => println!("Error fetching data: {}", e),
}
}
}
tokio
and async-std
provide async runtimes and utilities for managing asynchronous tasks.- They make it easy to handle multiple asynchronous operations concurrently.