You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a simple stream of TcpStream::connect futures, I want to process elements in stream concurrently so I used buffer_unordered, but I coundn't figure out how should I create future from new stream to run with tokio::run. Also some connection may be refused because of network condition, so I coulnd't use for_each over stream.
Here is the code so far:
externcrate bytes;externcrate tokio;use bytes::BytesMut;use tokio::io;use tokio::net::TcpStream;use tokio::prelude::*;fnmain(){let srv_list = vec!["127.0.0.1:12345",
"127.0.0.1:12346",
"127.0.0.1:12347",
"127.0.0.1:12348",
"127.0.0.1:12349",
];let conn_fut:Vec<_> = srv_list
.iter().map(|addr| {let addr = addr.parse().unwrap();TcpStream::connect(&addr).and_then(move |stream| {println!("connected to address: {:?}", addr);}).map_err(|err| {println!("couldn't connect, {:?}", err);})}).collect();let task = stream::iter_ok::<_,()>(conn_fut);let task = task.buffer_unordered(5);/* what should I do here?! */
tokio::run(task);}
The text was updated successfully, but these errors were encountered:
I have a simple stream of
TcpStream::connect
futures, I want to process elements in stream concurrently so I usedbuffer_unordered
, but I coundn't figure out how should I create future from new stream to run withtokio::run
. Also some connection may be refused because of network condition, so I coulnd't usefor_each
over stream.Here is the code so far:
The text was updated successfully, but these errors were encountered: