diff --git a/async-tcp/src/main.rs b/async-tcp/src/main.rs index 2eac0a7..653ddbc 100644 --- a/async-tcp/src/main.rs +++ b/async-tcp/src/main.rs @@ -3,11 +3,11 @@ extern crate bytes; extern crate futures; extern crate tokio; -use tokio::io::AsyncWrite; +use tokio::io::{self, AsyncWrite}; use tokio::net::{TcpStream, tcp::ConnectFuture}; use bytes::{Bytes, Buf}; use futures::{Future, Async, Poll}; -use std::io::{self, Cursor}; +use std::io::{Cursor}; enum HelloWorld { Connecting(ConnectFuture), @@ -47,4 +47,11 @@ fn main() { let hello_world = HelloWorld::Connecting(connect_future); tokio::run(hello_world.map_err(|e| println!("{0}", e))); + + let better_future = TcpStream::connect(&addr) + .and_then(|socket| io::write_all(socket, b"hello world")) + .map(|_| println!("write complete")) + .map_err(|_| println!("failed")); + + tokio::run(better_future); } diff --git a/future-hello-world/src/main.rs b/future-hello-world/src/main.rs index 6a46073..bbbdd0e 100644 --- a/future-hello-world/src/main.rs +++ b/future-hello-world/src/main.rs @@ -37,4 +37,6 @@ where fn main() { let future = Display(HelloWorld); tokio::run(future); + let better_future = HelloWorld.map(|value| println!("{}", value)); + tokio::run(better_future); }