async-std
async-std copied to clipboard
Add join_all function for waiting on an iterator of futures
Hi, everyone. Thank you for reading this issue. The crate futures has a function futures::future::join_all. But the performance of this function in futures seem not very good. Tokio has talked about this. Will async_std provide this function? I'm willing to work on this. If I add a vec marks in JoinAll to record ready futures to prevent poll them again, can solve this performance problem?
//struct JoinAll looks like this
pin_project! {
#[allow(missing_docs)]
#[allow(missing_debug_implementations)]
pub struct JoinAll<F>
where
F: Future,
{
#[pin] elems: Box<[MaybeDone<F>]>,
#[pin] marks: Box<Vec<u8>>,
}
}
// test
async_std::task::block_on(async {
use async_std::prelude::*;
use async_std::future;
let futurevec = vec![future::ready(5u8), future::ready(6u8)];
let join_all = future::ready(0).join_all(futurevec);
let result = join_all.await;
let mut count = 0;
for i in result.iter() {
println!("test count:{},result:{}", count, i);
count += 1;
}
assert_eq!(result, [5u8, 6u8]);
});