"new_debug_unreachable",
]
+[[package]]
+name = "futures"
+version = "0.3.31"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876"
+dependencies = [
+ "futures-channel",
+ "futures-core",
+ "futures-executor",
+ "futures-io",
+ "futures-sink",
+ "futures-task",
+ "futures-util",
+]
+
[[package]]
name = "futures-channel"
version = "0.3.31"
checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10"
dependencies = [
"futures-core",
+ "futures-sink",
]
[[package]]
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e"
+[[package]]
+name = "futures-executor"
+version = "0.3.31"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f"
+dependencies = [
+ "futures-core",
+ "futures-task",
+ "futures-util",
+]
+
[[package]]
name = "futures-io"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81"
dependencies = [
+ "futures-channel",
"futures-core",
"futures-io",
"futures-macro",
version = "0.1.0"
dependencies = [
"csv",
+ "futures",
"kalosm",
"rand 0.9.1",
"rayon",
+use futures::future::join_all;
use reqwest;
use rss::Channel;
}
async fn fetch_rss_feeds(urls: Vec<String>) -> Result<Vec<Channel>, Box<dyn std::error::Error>> {
- let mut channels = Vec::new();
- for url in urls {
- let channel = fetch_rss_feed(&url).await;
- if let Err(e) = channel {
- eprintln!("Error fetching {}: {}", url, e);
- continue;
- } else if let Ok(channell) = channel {
- channels.push(channell);
- }
- }
+ let futures = urls.iter().map(|url| fetch_rss_feed(url));
+ let results: Vec<Result<Channel, Box<dyn std::error::Error>>> = join_all(futures).await;
+
+ let channels: Vec<Channel> = results
+ .into_iter()
+ .zip(urls.iter())
+ .filter_map(|(result, url)| match result {
+ Ok(channel) => Some(channel),
+ Err(e) => {
+ eprintln!("Error fetching {}: {}", url, e);
+ None
+ }
+ })
+ .collect();
+
Ok(channels)
}