I have a ton of futures (~100) and I don't care in what order they're done. I'd like for multiple futures to be "in-flight" at once (around 4 futures to be worked on at the same time).
I'm using tokio and I expected something like FuturesUnordered to poll multiple futures at once. I wrote this:
let client = ClientBuilder::new().build().ok()?;
let result = files.iter()
.map(|file| download_file(&client, url, file.clone())) // Returns Result<(String, Vec<u8>), ...>
.collect::<FuturesUnordered<_>>()
.collect::<Vec<_>>() // Collecting into a vec here since I'm not sure how to filter
.await
.into_iter()
.filter_map(|x| x.ok())
.collect::<HashMap<String, Vec<u8>>>();
But with this code, we can clearly see one async call is being processed at a time. Yikes! How can I ask it to dispatch multiple async calls at once?