Imagine that some futures are stored in a Vec
whose length are runtime-determined, you are supposed to join these futures concurrently, what should you do?
Obviously, by the example in the document of tokio::join
, manually specifying each length the Vec
could be, like 1, 2, 3, ... and dealing with respectable case should work.
extern crate tokio;
let v = Vec::new();
v.push(future_1);
// directly or indirectly you push many futures to the vector
v.push(future_N);
// to join these futures concurrently one possible way is
if v.len() == 0 {}
if v.len() == 1 { join!(v.pop()); }
if v.len() == 2 { join!(v.pop(), v.pop() ); }
// ...
And I also noticed that tokio::join!
take a list as parameter in the document, when I use syntax like
tokio::join!(v);
or something like
tokio::join![ v ] / tokio::join![ v[..] ] / tokio::join![ v[..][..] ]
it just doesn't work
And here comes the question that is there any doorway to join these futures more efficient or should I miss something against what the document says?
tokio::join!
takes a variable number of async expressions, not a single slice / vec of async values. – IntroductoryJoinSet
should be the direct and spot-on answer for your question. Hope one day you can come back and give the man his kudos. I was looking for something like this as well, having known there'sjoin_all
fromfutures
; but at times one would want one dependency only. – Untidy