let futures = ... .collect::<FuturesUnordered<_>>();
while let Some(_result) = futures.next().await {}
There might be a way of using for_each() to drain the iterator but I think it might require async closures in this case. Still learning so wondering what others will suggest.
Vec<()> doesn't allocate on the heap, since () is a zero sized type. As long as you're not returning a value from the future, its already doing what you want.
In the Guarantees section of the Vec documentation:
Similarly, if you store zero-sized types inside a Vec, it will not allocate space for them. Note that in this case the Vec may not report a capacity of 0. Vec will allocate if and only if mem::size_of::<T>() * capacity() > 0 .
I was wondering what happens to the length. Does Vec become essentially an usize or is the Vec struct allocated without elements? As perhaps suggested by
Most fundamentally, Vec is and always will be a (pointer, capacity, length) triplet. No more, no less.
Code
fn test(_i: i64) {}
fn main() {
let v = (0..100).map(test).collect::<Vec<_>>();
println!("{}", v.len());
}
You could check the code for Vec::new(), which shows that a 3-usize struct is allocated with len = 0. Note that the underlying Raw_vec::new() initializes the capacity to zero when mem::size_of::<T>() > 0, and to usize::MAX whtn mem::size_of::<T>() = 0,