async-tcp & future-hello: use better futures functions
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user