diff options
author | Carl Lerche <me@carllerche.com> | 2017-10-25 10:54:54 -0700 |
---|---|---|
committer | Carl Lerche <me@carllerche.com> | 2017-11-01 07:28:49 -0700 |
commit | c6f1ff13d249a42a5d0ae716dffca6a22cd1d7ca (patch) | |
tree | 7d5845668553eea08013cb75fdfbc4cb4f629255 /examples/tinyhttp.rs | |
parent | 697851210c13e3df637a93af526cf6e41a217cfd (diff) |
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.
Diffstat (limited to 'examples/tinyhttp.rs')
-rw-r--r-- | examples/tinyhttp.rs | 11 |
1 files changed, 8 insertions, 3 deletions
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<net::TcpStream>) { 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<net::TcpStream>) { 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<net::TcpStream>) { /// represents the various handling a server might do. Currently the contents /// here are pretty uninteresting. fn respond(req: Request<()>) - -> Box<Future<Item = Response<String>, Error = io::Error>> + -> Box<Future<Item = Response<String>, Error = io::Error> + Send> { let mut ret = Response::builder(); let body = match req.uri().path() { |