Skip to content

Instantly share code, notes, and snippets.

@trizinix
Created January 4, 2017 16:59
Show Gist options
  • Save trizinix/8544b398003f7c84a88034ee44f29cb3 to your computer and use it in GitHub Desktop.
Save trizinix/8544b398003f7c84a88034ee44f29cb3 to your computer and use it in GitHub Desktop.
fn writeall_stdout(socket: TcpStream) -> IoFuture<()> {
let iter = iter::repeat(()).map(|()| Ok(()));
stream::iter(iter).fold(socket, move |socket, ()| {
let buf = vec![0;1024];
tokio_core::io::read(socket, buf).map(|(socket, _, num_bytes)| {
println!("Read {} bytes", num_bytes);
socket
})
}).map(|_| ()).boxed()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment