Use tokio_core instead of runtime as top loop
This commit is contained in:
parent
49541347a4
commit
ee82846590
3 changed files with 14 additions and 6 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -598,6 +598,7 @@ dependencies = [
|
||||||
"hyper 0.11.25 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"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 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)",
|
"tokio-io 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -10,4 +10,5 @@ futures = "0.1.20"
|
||||||
hyper = "0.11.25"
|
hyper = "0.11.25"
|
||||||
odds = { version = "0.3.1", features = ["std-vec"] }
|
odds = { version = "0.3.1", features = ["std-vec"] }
|
||||||
tokio = "0.1.5"
|
tokio = "0.1.5"
|
||||||
|
tokio-core = "0.1.17"
|
||||||
tokio-io = "0.1.6"
|
tokio-io = "0.1.6"
|
||||||
|
|
18
src/main.rs
18
src/main.rs
|
@ -2,6 +2,7 @@
|
||||||
extern crate futures;
|
extern crate futures;
|
||||||
extern crate hyper;
|
extern crate hyper;
|
||||||
extern crate tokio;
|
extern crate tokio;
|
||||||
|
extern crate tokio_core;
|
||||||
extern crate tokio_io;
|
extern crate tokio_io;
|
||||||
extern crate webmetro;
|
extern crate webmetro;
|
||||||
|
|
||||||
|
@ -9,6 +10,7 @@ mod commands;
|
||||||
|
|
||||||
use clap::{App, AppSettings};
|
use clap::{App, AppSettings};
|
||||||
use futures::prelude::*;
|
use futures::prelude::*;
|
||||||
|
use tokio_core::reactor::Core;
|
||||||
use webmetro::error::WebmetroError;
|
use webmetro::error::WebmetroError;
|
||||||
|
|
||||||
use commands::{
|
use commands::{
|
||||||
|
@ -30,7 +32,10 @@ fn options() -> App<'static, 'static> {
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = options().get_matches();
|
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)),
|
("filter", Some(sub_args)) => box_up(filter::run(sub_args)),
|
||||||
("relay", Some(sub_args)) => box_up(relay::run(sub_args)),
|
("relay", Some(sub_args)) => box_up(relay::run(sub_args)),
|
||||||
("dump", Some(sub_args)) => box_up(dump::run(sub_args)),
|
("dump", Some(sub_args)) => box_up(dump::run(sub_args)),
|
||||||
|
@ -42,14 +47,15 @@ fn main() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tokio_run(task: Box<Future<Item=(), Error=WebmetroError> + Send + 'static>) {
|
fn tokio_run(mut core: Core, task: Box<Future<Item=(), Error=WebmetroError>>) {
|
||||||
tokio::run(task.into_future().map_err(|err| {
|
core.run(task.into_future()).unwrap_or_else(|err| {
|
||||||
eprintln!("Error: {}", err);
|
eprintln!("Error: {}", err);
|
||||||
::std::process::exit(1);
|
::std::process::exit(1);
|
||||||
}));
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn box_up<F: IntoFuture<Item=(), Error=WebmetroError>>(task: F) -> Box<Future<Item=(), Error=WebmetroError> + Send + 'static>
|
fn box_up<F: IntoFuture<Item=(), Error=WebmetroError>>(task: F) -> Box<Future<Item=(), Error=WebmetroError>>
|
||||||
where F::Future: Send + 'static {
|
where F::Future: 'static
|
||||||
|
{
|
||||||
Box::new(task.into_future())
|
Box::new(task.into_future())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue