-
Notifications
You must be signed in to change notification settings - Fork 655
Open
Labels
Description
In the documentation of FuturesUnordered
it's written
"When new futures are added, poll_next must be called in order to begin receiving wake-ups for new futures."
Does it mean that if I consume the FuturesUnordered
as a Stream
and there is no more futures inside it, it would return None
but if then later I add a future, it will return Some
again?
In the current implementation, this seems to be the case:
use std::time::Duration;
use futures::stream::{FusedStream, FuturesUnordered};
use futures::StreamExt;
fn main() {
tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap().block_on(run())
}
async fn run() {
let mut fuo = [f(), f()].into_iter().collect::<FuturesUnordered<_>>();
assert!(fuo.next().await.is_some());
assert!(fuo.next().await.is_some());
assert!(fuo.next().await.is_none());
assert!(fuo.is_terminated());
fuo.push(f());
assert!(fuo.next().await.is_some());
println!("Done !");
}
async fn f() {
tokio::time::sleep(Duration::from_millis(100)).await;
}
Is it a behavior I can rely upon? In other words, is this guarantee by FuturesUnordered
?
Tudyx and nazar-pc