Use hyper-provided runtime instead of tokio-core

This commit is contained in:
Tangent 2018-09-18 02:29:01 -04:00
parent 14d468cc7d
commit 08e8b1311f
4 changed files with 9 additions and 43 deletions
src

View file

@ -8,9 +8,6 @@ use hyper::{
client::HttpConnector,
Request
};
use tokio_core::reactor::{
Handle
};
use super::{
stdin_stream,
@ -39,7 +36,7 @@ pub fn options() -> App<'static, 'static> {
type BoxedChunkStream = Box<Stream<Item = Chunk, Error = WebmetroError> + Send>;
pub fn run(_handle: Handle, args: &ArgMatches) -> Box<Future<Item=(), Error=WebmetroError>> {
pub fn run(args: &ArgMatches) -> Box<Future<Item=(), Error=WebmetroError> + Send> {
let mut chunk_stream: BoxedChunkStream = Box::new(
stdin_stream()
.parse_ebml()

View file

@ -3,7 +3,6 @@ extern crate futures;
extern crate http;
extern crate hyper;
extern crate tokio;
extern crate tokio_core;
extern crate tokio_io;
extern crate webmetro;
@ -11,7 +10,7 @@ mod commands;
use clap::{App, AppSettings};
use futures::prelude::*;
use tokio_core::reactor::Core;
use hyper::rt;
use webmetro::error::WebmetroError;
use commands::{
@ -36,13 +35,10 @@ fn options() -> App<'static, 'static> {
fn main() {
let args = options().get_matches();
let core = Core::new().unwrap();
let handle = core.handle();
tokio_run(core, match args.subcommand() {
tokio_run(match args.subcommand() {
("filter", Some(sub_args)) => box_up(filter::run(sub_args)),
("relay", Some(sub_args)) => box_up(relay::run(sub_args)),
("send", Some(sub_args)) => box_up(send::run(handle, sub_args)),
("send", Some(sub_args)) => box_up(send::run(sub_args)),
("dump", Some(sub_args)) => box_up(dump::run(sub_args)),
_ => box_up(futures::lazy(|| {
options().print_help().unwrap();
@ -52,15 +48,15 @@ fn main() {
});
}
fn tokio_run(mut core: Core, task: Box<Future<Item=(), Error=WebmetroError>>) {
core.run(task.into_future()).unwrap_or_else(|err| {
fn tokio_run(task: Box<Future<Item=(), Error=WebmetroError> + Send>) {
rt::run(task.into_future().map_err(|err| {
eprintln!("Error: {}", err);
::std::process::exit(1);
});
}));
}
fn box_up<F: IntoFuture<Item=(), Error=WebmetroError>>(task: F) -> Box<Future<Item=(), Error=WebmetroError>>
where F::Future: 'static
fn box_up<F: IntoFuture<Item=(), Error=WebmetroError>>(task: F) -> Box<Future<Item=(), Error=WebmetroError> + Send>
where F::Future: Send + 'static
{
Box::new(task.into_future())
}