diff --git a/Cargo.lock b/Cargo.lock index 559258a..2d36767 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -598,6 +598,7 @@ dependencies = [ "hyper 0.11.25 (registry+https://github.com/rust-lang/crates.io-index)", "odds 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-core 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/Cargo.toml b/Cargo.toml index 99d0239..7a72521 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,4 +10,5 @@ futures = "0.1.20" hyper = "0.11.25" odds = { version = "0.3.1", features = ["std-vec"] } tokio = "0.1.5" +tokio-core = "0.1.17" tokio-io = "0.1.6" diff --git a/src/main.rs b/src/main.rs index 5278bc9..71abbe0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ extern crate futures; extern crate hyper; extern crate tokio; +extern crate tokio_core; extern crate tokio_io; extern crate webmetro; @@ -9,6 +10,7 @@ mod commands; use clap::{App, AppSettings}; use futures::prelude::*; +use tokio_core::reactor::Core; use webmetro::error::WebmetroError; use commands::{ @@ -30,7 +32,10 @@ fn options() -> App<'static, 'static> { fn main() { let args = options().get_matches(); - tokio_run(match args.subcommand() { + let core = Core::new().unwrap(); + let handle = core.handle(); + + tokio_run(core, match args.subcommand() { ("filter", Some(sub_args)) => box_up(filter::run(sub_args)), ("relay", Some(sub_args)) => box_up(relay::run(sub_args)), ("dump", Some(sub_args)) => box_up(dump::run(sub_args)), @@ -42,14 +47,15 @@ fn main() { }); } -fn tokio_run(task: Box + Send + 'static>) { - tokio::run(task.into_future().map_err(|err| { +fn tokio_run(mut core: Core, task: Box>) { + core.run(task.into_future()).unwrap_or_else(|err| { eprintln!("Error: {}", err); ::std::process::exit(1); - })); + }); } -fn box_up>(task: F) -> Box + Send + 'static> -where F::Future: Send + 'static { +fn box_up>(task: F) -> Box> +where F::Future: 'static +{ Box::new(task.into_future()) }