我正在尝试将期货附加到BufferUnordered
的基础流。目前我将它们直接推入底层流中,Fuse
BufferUnordered
流为空,因此推送到它没有任何效果,下面的循环不会收到第三个响应。将next
(1)的定义更改为stream.buffer_unordered(1)
似乎可以使其工作,因为基础流不是空的/已完成。
extern crate url;
extern crate futures;
extern crate tokio_core;
extern crate reqwest;
use url::Url;
use futures::*;
use tokio_core::reactor::Core;
use reqwest::unstable::async::{Client, Response, Decoder};
fn main() {
let mut core = Core::new().unwrap();
let client = Client::new(&core.handle()).unwrap();
let hyper = client.get("https://hyper.rs").unwrap().send();
let google = client.get("https://google.com").unwrap().send();
let stream = stream::futures_unordered(vec![future::ok(hyper), future::ok(google)]);
let mut next = stream.buffer_unordered(5).into_future(); // (1)
loop {
match core.run(next) {
Ok((None, _something)) => {
println!("finished");
break;
},
Ok((Some(response), mut next_requests)) => {
{
let inner = next_requests.get_mut();
println!("{}", inner.is_empty());
println!("{}", response.status());
let yahoo = client.get("https://yahoo.com").unwrap().send();
inner.push(future::ok(yahoo)); // no effect here
}
next = next_requests.into_future();
}
Err((error, next_requests)) => {
next = next_requests.into_future();
}
}
}
}
如何向BufferUnordered
添加更多期货?我是否真的必须将它链接起来或沿着这些方向做某事?