futures-rs icon indicating copy to clipboard operation
futures-rs copied to clipboard

Question: wait for futures that return no result to complete

Open Enigo opened this issue 2 years ago • 0 comments

I need to perform ~20k API calls. To speed things up I wanted to execute them in parallel + using buffer_unordered My code looks like this:

pub async fn read() {
    let ids: Vec<i32> = (1..20000).collect();
    let mut futures = futures::stream::iter(ids)
        .map(|id| process_id(id))
        .buffer_unordered(15);

    // waiting for all to complete
    while let Some(_) = futures.next().await {}
}

async fn process_id(id: i32) {
    // API call is here
}

Question - is it an idiomatic way to wait for futures that return no result? I'm referring to this part: while let Some(_) = futures.next().await {}

Thanks!

Enigo avatar Jan 28 '23 09:01 Enigo