]> git.taranathan.com Git - scrape.git/commitdiff
fix
authormoo <moogoesmeow123@gmail.com>
Sat, 26 Jul 2025 05:42:00 +0000 (22:42 -0700)
committermoo <moogoesmeow123@gmail.com>
Sat, 26 Jul 2025 05:42:00 +0000 (22:42 -0700)
src/fetch.rs

index e49d46b8fcef64335622cd89fb953478466c6393..a8b909580eea2abf2be5f31fcd5544ac2db2f51f 100644 (file)
@@ -7,8 +7,32 @@ pub async fn fetch(urls: Vec<String>) -> Result<Vec<String>, Box<dyn std::error:
 }
 
 async fn fetch_rss_feeds(urls: Vec<String>) -> Result<Vec<Channel>, Box<dyn std::error::Error>> {
+    // 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)
+
     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 mut futures_unordered = FuturesUnordered::new();
+
+    for future in futures {
+        futures_unordered.push(future);
+    }
+
+    let results: Vec<Result<Channel, Box<dyn std::error::Error>>> =
+        futures_unordered.collect().await;
 
     let channels: Vec<Channel> = results
         .into_iter()
@@ -23,31 +47,6 @@ async fn fetch_rss_feeds(urls: Vec<String>) -> Result<Vec<Channel>, Box<dyn std:
         .collect();
 
     Ok(channels)
-
-//================================================================
-
-let futures = urls.iter().map(|url| fetch_rss_feed(url));
-let mut futures_unordered = FuturesUnordered::new();
-
-for future in futures {
-    futures_unordered.push(future);
-}
-
-let results: Vec<Result<Channel, Box<dyn std::error::Error>>> = futures_unordered.collect().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)
 }
 
 async fn fetch_rss_feed(url: &str) -> Result<Channel, Box<dyn std::error::Error>> {