async-tcp & future-hello: use better futures functions

This commit is contained in:
2019-01-25 18:09:59 +01:00
parent b439b235f8
commit 5b59369043
2 changed files with 11 additions and 2 deletions

View File

@@ -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);
}