Switch back to futures from crates.io (#113)

Doing so requires copying the `current_thread` executor from GitHub into
the repo.
This commit is contained in:
Carl Lerche
2018-02-06 07:26:21 -08:00
committed by GitHub
parent 567887cc75
commit f0ea9d6f4c
31 changed files with 1313 additions and 70 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::{self, Executor};
use futures::future::Executor;
use futures::stream::{self, Stream};
use futures_cpupool::CpuPool;
use tokio::net::TcpListener;
@@ -134,5 +134,5 @@ fn main() {
});
// execute server
future::blocking(srv).wait().unwrap();
srv.wait().unwrap();
}
+1 -1
View File
@@ -33,10 +33,10 @@ extern crate tokio;
extern crate tokio_io;
extern crate bytes;
use tokio::executor::current_thread;
use tokio::net::{TcpListener, TcpStream};
use tokio_io::{AsyncRead};
use futures::prelude::*;
use futures::current_thread;
use futures::sync::mpsc;
use futures::future::{self, Either};
use bytes::{BytesMut, Bytes, BufMut};
+2 -2
View File
@@ -29,7 +29,7 @@ use std::env;
use std::net::SocketAddr;
use futures::{Future, Stream, Poll};
use futures::future::{self, Executor};
use futures::future::Executor;
use futures_cpupool::CpuPool;
use tokio::net::{TcpListener, TcpStream};
use tokio_io::{AsyncRead, AsyncWrite};
@@ -62,7 +62,7 @@ fn main() {
Ok(())
});
future::blocking(server).wait().unwrap();
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::{future, Sink, 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();
future::blocking(stdout.for_each(|chunk| {
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 future::blocking(tx.send(buf)).wait() {
tx = match 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::{self, Executor};
use futures::future::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(())
});
future::blocking(srv).wait().unwrap();
srv.wait().unwrap();
}
fn worker(rx: mpsc::UnboundedReceiver<TcpStream>) {
@@ -88,5 +88,5 @@ fn worker(rx: mpsc::UnboundedReceiver<TcpStream>) {
Ok(())
});
future::blocking(done).wait().unwrap();
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, Future, Poll};
use futures::{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
future::blocking(Server {
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::{self, Executor};
use futures::future::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.
future::blocking(done).wait().unwrap();
done.wait().unwrap();
}
+1 -2
View File
@@ -19,7 +19,6 @@ extern crate tokio_io;
use std::env;
use std::net::SocketAddr;
use futures::future;
use futures::prelude::*;
use tokio::net::TcpListener;
@@ -41,5 +40,5 @@ fn main() {
Ok(())
});
future::blocking(server).wait().unwrap();
server.wait().unwrap();
}
+2 -1
View File
@@ -18,9 +18,10 @@ extern crate tokio;
extern crate tokio_io;
extern crate futures;
use tokio::executor::current_thread;
use tokio::net::TcpListener;
use tokio_io::io;
use futures::{current_thread, Future, Stream};
use futures::{Future, Stream};
pub fn main() {
let addr = "127.0.0.1:6142".parse().unwrap();
+3 -2
View File
@@ -28,7 +28,7 @@ use std::io::{self, Read, Write};
use futures::stream::Stream;
use futures::{Future, Poll};
use futures::future::{self, Executor};
use futures::future::{Executor};
use futures_cpupool::CpuPool;
use tokio::net::{TcpListener, TcpStream};
use tokio_io::{AsyncRead, AsyncWrite};
@@ -92,7 +92,8 @@ fn main() {
Ok(())
});
future::blocking(done).wait().unwrap();
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::{self, Executor};
use futures::future::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(())
});
future::blocking(server).wait().unwrap();
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::{self, Executor};
use futures::future::Executor;
use futures_cpupool::CpuPool;
use tokio::net::TcpListener;
use tokio_io::AsyncRead;
@@ -160,7 +160,7 @@ fn main() {
Ok(())
});
future::blocking(done).wait().unwrap();
done.wait().unwrap();
}
impl Request {
+1 -1
View File
@@ -90,7 +90,7 @@ fn worker(rx: mpsc::UnboundedReceiver<net::TcpStream>) {
})).unwrap();
Ok(())
});
future::blocking(done).wait().unwrap();
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::{self, Executor};
use futures::future::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(future::blocking(a).wait());
drop(a.wait());
}