I have a list of async
functions in rust that I want to execute concurrently and then wait for all them to finish. The working code I have right now is
So after some searching I found that rust futures has a function called join_all which allows for waiting on a collection of futures.
use futures::future::join_all;
....
async fn start_consumers(&self) {
let mut v = Vec::new();
for consumer in &self.consumers {
v.push(consumer.consume());
}
join_all(v).await;
}
I also asked a similar question on the same day, but in my case I had a Result
wrapped in a Future
. So instead of join_all
I had to use try_join_all