I am using the roux - Rust library for Reddit API access and want to download all my Content. (Saved Items, Submissions and Comments)
The library is async by default, so I have functions like this
// TODO Check order of saved items
pub fn get_saved_item_stream(account: &Me) -> impl Stream<Item = Content> + '_ {
let mut after_id: Option<String> = None;
stream! {
loop {
let saved_items = match account.saved(after_id.as_ref().map(|aid| FeedOption::new().after(aid))).await {
Ok(saved) => {
after_id = saved.data.after;
saved.data.children
},
Err(_) => vec![],
};
for saved_item in saved_items {
yield Content::try_from(saved_item.data).unwrap();
}
if after_id.is_none() {
break;
}
}
}
}
To get a stream of my saved items. I would ultimately write this stream to some file in a serialized format.
Similarly I have two more streams (One for submissions, other for comments) and I would write those into their own files as well (submissions.json, comments.json maybe?)
pub fn get_submission_stream(account: &Me) -> impl Stream<Item = Content> + '_ {
// .....
}
pub fn get_comment_stream(account: &Me) -> impl Stream<Item = Content> + '_ {
// .....
}
My issue is I don't see how I am benefiting from async here. The only parallelization I can think of is I can parallel write to the 3 files from the 3 async streams. But how would I do that? File I/O is synchronous in the background right? Is it even useful/possible?
Alternatively, the Roux library has a blocking feature. I can convert those streams to Iterators and just use blocking functions for file writing?
I am not sure what is the right approach here, probably because I still have a hard time wrapping my head around how async works and what it's benefits are. Would appreciate any insights.