Track futures tokio-reform branch (#88)

This patch also updates tests and examples to remove deprecated API
usage.
This commit is contained in:
Carl Lerche
2018-02-01 10:31:07 -08:00
committed by GitHub
parent b9db119b45
commit 2e94b658ed
24 changed files with 66 additions and 57 deletions
+2 -2
View File
@@ -29,7 +29,7 @@ use std::io::{Error, ErrorKind, BufReader};
use std::sync::{Arc, Mutex};
use futures::Future;
use futures::future::Executor;
use futures::future::{self, Executor};
use futures::stream::{self, Stream};
use futures_cpupool::CpuPool;
use tokio::net::TcpListener;
@@ -134,5 +134,5 @@ fn main() {
});
// execute server
srv.wait().unwrap();
future::blocking(srv).wait().unwrap();
}
+2 -2
View File
@@ -29,7 +29,7 @@ use std::env;
use std::net::SocketAddr;
use futures::{Future, Stream, Poll};
use futures::future::Executor;
use futures::future::{self, Executor};
use futures_cpupool::CpuPool;
use tokio::net::{TcpListener, TcpStream};
use tokio_io::{AsyncRead, AsyncWrite};
@@ -62,7 +62,7 @@ fn main() {
Ok(())
});
server.wait().unwrap();
future::blocking(server).wait().unwrap();
}
/// The main workhorse of this example. This'll compress all data read from
+4 -4
View File
@@ -26,7 +26,7 @@ use std::net::SocketAddr;
use std::thread;
use futures::sync::mpsc;
use futures::{Sink, Future, Stream};
use futures::{future, Sink, Stream};
use futures_cpupool::CpuPool;
fn main() {
@@ -71,9 +71,9 @@ fn main() {
// loop. In this case, though, we know it's ok as the event loop isn't
// otherwise running anything useful.
let mut out = io::stdout();
stdout.for_each(|chunk| {
future::blocking(stdout.for_each(|chunk| {
out.write_all(&chunk)
}).wait().unwrap();
})).wait().unwrap();
}
mod tcp {
@@ -244,7 +244,7 @@ fn read_stdin(mut tx: mpsc::Sender<Vec<u8>>) {
Ok(n) => n,
};
buf.truncate(n);
tx = match tx.send(buf).wait() {
tx = match future::blocking(tx.send(buf)).wait() {
Ok(tx) => tx,
Err(_) => break,
};
+3 -3
View File
@@ -24,7 +24,7 @@ use std::net::SocketAddr;
use std::thread;
use futures::prelude::*;
use futures::future::Executor;
use futures::future::{self, Executor};
use futures::sync::mpsc;
use futures_cpupool::CpuPool;
use tokio_io::AsyncRead;
@@ -61,7 +61,7 @@ fn main() {
next = (next + 1) % channels.len();
Ok(())
});
srv.wait().unwrap();
future::blocking(srv).wait().unwrap();
}
fn worker(rx: mpsc::UnboundedReceiver<TcpStream>) {
@@ -88,5 +88,5 @@ fn worker(rx: mpsc::UnboundedReceiver<TcpStream>) {
Ok(())
});
done.wait().unwrap();
future::blocking(done).wait().unwrap();
}
+3 -3
View File
@@ -18,7 +18,7 @@ extern crate tokio_io;
use std::{env, io};
use std::net::SocketAddr;
use futures::{Future, Poll};
use futures::{future, Future, Poll};
use tokio::net::UdpSocket;
struct Server {
@@ -58,9 +58,9 @@ fn main() {
// Next we'll create a future to spawn (the one we defined above) and then
// we'll block our current thread waiting on the result of the future
Server {
future::blocking(Server {
socket: socket,
buf: vec![0; 1024],
to_send: None,
}.wait().unwrap();
}).wait().unwrap();
}
+2 -2
View File
@@ -26,7 +26,7 @@ use std::env;
use std::net::SocketAddr;
use futures::Future;
use futures::future::Executor;
use futures::future::{self, Executor};
use futures::stream::Stream;
use futures_cpupool::CpuPool;
use tokio_io::AsyncRead;
@@ -114,5 +114,5 @@ fn main() {
// And finally now that we've define what our server is, we run it! Here we
// just need to execute the future we've created and wait for it to complete
// using the standard methods in the `futures` crate.
done.wait().unwrap();
future::blocking(done).wait().unwrap();
}
+2 -1
View File
@@ -19,6 +19,7 @@ extern crate tokio_io;
use std::env;
use std::net::SocketAddr;
use futures::future;
use futures::prelude::*;
use tokio::net::TcpListener;
@@ -40,5 +41,5 @@ fn main() {
Ok(())
});
server.wait().unwrap();
future::blocking(server).wait().unwrap();
}
+2 -2
View File
@@ -28,7 +28,7 @@ use std::io::{self, Read, Write};
use futures::stream::Stream;
use futures::{Future, Poll};
use futures::future::Executor;
use futures::future::{self, Executor};
use futures_cpupool::CpuPool;
use tokio::net::{TcpListener, TcpStream};
use tokio_io::{AsyncRead, AsyncWrite};
@@ -92,7 +92,7 @@ fn main() {
Ok(())
});
done.wait().unwrap();
future::blocking(done).wait().unwrap();
}
// This is a custom type used to have a custom implementation of the
+2 -2
View File
@@ -26,7 +26,7 @@ use std::iter;
use std::net::SocketAddr;
use futures::Future;
use futures::future::Executor;
use futures::future::{self, Executor};
use futures::stream::{self, Stream};
use futures_cpupool::CpuPool;
use tokio_io::IoFuture;
@@ -46,7 +46,7 @@ fn main() {
pool.execute(write(socket).or_else(|_| Ok(()))).unwrap();
Ok(())
});
server.wait().unwrap();
future::blocking(server).wait().unwrap();
}
fn write(socket: TcpStream) -> IoFuture<()> {
+2 -2
View File
@@ -51,7 +51,7 @@ use std::net::SocketAddr;
use std::sync::{Arc, Mutex};
use futures::prelude::*;
use futures::future::Executor;
use futures::future::{self, Executor};
use futures_cpupool::CpuPool;
use tokio::net::TcpListener;
use tokio_io::AsyncRead;
@@ -160,7 +160,7 @@ fn main() {
Ok(())
});
done.wait().unwrap();
future::blocking(done).wait().unwrap();
}
impl Request {
+2 -3
View File
@@ -31,8 +31,7 @@ use std::net::{self, SocketAddr};
use std::thread;
use bytes::BytesMut;
use futures::future::Executor;
use futures::future;
use futures::future::{self, Executor};
use futures::sync::mpsc;
use futures::{Stream, Future, Sink};
use futures_cpupool::CpuPool;
@@ -91,7 +90,7 @@ fn worker(rx: mpsc::UnboundedReceiver<net::TcpStream>) {
})).unwrap();
Ok(())
});
done.wait().unwrap();
future::blocking(done).wait().unwrap();
}
/// "Server logic" is implemented in this function.
+2 -2
View File
@@ -15,7 +15,7 @@ use std::io;
use std::net::SocketAddr;
use futures::{Future, Stream, Sink};
use futures::future::Executor;
use futures::future::{self, Executor};
use futures_cpupool::CpuPool;
use tokio::net::{UdpSocket, UdpCodec};
@@ -76,5 +76,5 @@ fn main() {
// Spawn the sender of pongs and then wait for our pinger to finish.
pool.execute(b.then(|_| Ok(()))).unwrap();
drop(a.wait());
drop(future::blocking(a).wait());
}