blob: ee904ab185df1f79cd0c2e79af4b5790a62a92a6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
use futures::{StreamExt, stream};
use isahc::AsyncReadResponseExt;
use rss::Channel;
pub async fn retrieve<'a, I>(urls: I) -> Vec<Channel>
where I : IntoIterator<Item = &'a str>
{
stream::iter(urls)
.flat_map(|url| stream::once(retrieve_one_or_warn(url)))
.filter_map(async |result| result.ok())
.collect().await
}
async fn retrieve_one_or_warn(url: &str) -> anyhow::Result<Channel>
{
retrieve_one(url).await
.inspect_err(|err| eprintln!("Failed to fetch {url}: {:#?}", err))
}
async fn retrieve_one(url: &str) -> anyhow::Result<Channel>
{
let content = isahc::get_async(url).await?.bytes().await?;
Ok(Channel::read_from(&content[..])?)
}
|