Remove executor from reactor.

In accordance with tokio-rs/tokio-rfcs#3, the executor functionality of
Tokio is being removed and will be relocated into futures-rs as a
"current thread" executor.

This PR removes task execution from the code base. As a temporary
mesure, all examples and tests are switched to using CpuPool.

Depends on #19.
This commit is contained in:
Carl Lerche
2017-11-01 07:28:49 -07:00
parent 697851210c
commit c6f1ff13d2
14 changed files with 117 additions and 186 deletions
+12 -6
View File
@@ -18,6 +18,7 @@
//! should be able to see them all make progress simultaneously.
extern crate futures;
extern crate futures_cpupool;
extern crate tokio;
extern crate tokio_io;
@@ -25,7 +26,9 @@ use std::env;
use std::net::SocketAddr;
use futures::Future;
use futures::future::Executor;
use futures::stream::Stream;
use futures_cpupool::CpuPool;
use tokio_io::AsyncRead;
use tokio_io::io::copy;
use tokio::net::TcpListener;
@@ -46,7 +49,7 @@ fn main() {
//
// After the event loop is created we acquire a handle to it through the
// `handle` method. With this handle we'll then later be able to create I/O
// objects and spawn futures.
// objects.
let mut core = Core::new().unwrap();
let handle = core.handle();
@@ -58,6 +61,9 @@ fn main() {
let socket = TcpListener::bind(&addr, &handle).unwrap();
println!("Listening on: {}", addr);
// A CpuPool allows futures to be executed concurrently.
let pool = CpuPool::new(1);
// Here we convert the `TcpListener` to a stream of incoming connections
// with the `incoming` method. We then define how to process each element in
// the stream with the `for_each` method.
@@ -105,16 +111,16 @@ fn main() {
// And this is where much of the magic of this server happens. We
// crucially want all clients to make progress concurrently, rather than
// blocking one on completion of another. To achieve this we use the
// `spawn` function on `Handle` to essentially execute some work in the
// background.
// `execute` function on the `Executor` trait to essentially execute
// some work in the background.
//
// This function will transfer ownership of the future (`msg` in this
// case) to the event loop that `handle` points to. The event loop will
// then drive the future to completion.
//
// Essentially here we're spawning a new task to run concurrently, which
// will allow all of our clients to be processed concurrently.
handle.spawn(msg);
// Essentially here we're executing a new task to run concurrently,
// which will allow all of our clients to be processed concurrently.
pool.execute(msg).unwrap();
Ok(())
});