From c6f1ff13d249a42a5d0ae716dffca6a22cd1d7ca Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Wed, 25 Oct 2017 10:54:54 -0700 Subject: 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. --- examples/tinyhttp.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'examples/tinyhttp.rs') diff --git a/examples/tinyhttp.rs b/examples/tinyhttp.rs index 043e56d2..2dddaf08 100644 --- a/examples/tinyhttp.rs +++ b/examples/tinyhttp.rs @@ -13,6 +13,7 @@ extern crate bytes; extern crate futures; +extern crate futures_cpupool; extern crate http; extern crate httparse; extern crate num_cpus; @@ -31,8 +32,10 @@ use std::thread; use bytes::BytesMut; use futures::future; +use futures::future::Executor; use futures::sync::mpsc; use futures::{Stream, Future, Sink}; +use futures_cpupool::CpuPool; use http::{Request, Response, StatusCode}; use http::header::HeaderValue; use tokio::net::TcpStream; @@ -69,6 +72,8 @@ fn worker(rx: mpsc::UnboundedReceiver) { let mut core = Core::new().unwrap(); let handle = core.handle(); + let pool = CpuPool::new(1); + let done = rx.for_each(move |socket| { // Associate each socket we get with our local event loop, and then use // the codec support in the tokio-io crate to deal with discrete @@ -80,10 +85,10 @@ fn worker(rx: mpsc::UnboundedReceiver) { let (tx, rx) = socket.framed(Http).split(); tx.send_all(rx.and_then(respond)) }); - handle.spawn(req.then(move |result| { + pool.execute(req.then(move |result| { drop(result); Ok(()) - })); + })).unwrap(); Ok(()) }); core.run(done).unwrap(); @@ -95,7 +100,7 @@ fn worker(rx: mpsc::UnboundedReceiver) { /// represents the various handling a server might do. Currently the contents /// here are pretty uninteresting. fn respond(req: Request<()>) - -> Box, Error = io::Error>> + -> Box, Error = io::Error> + Send> { let mut ret = Response::builder(); let body = match req.uri().path() { -- cgit v1.2.3