diff --git a/Cargo.lock b/Cargo.lock index 9e49d72..b8b8501 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1086,7 +1086,6 @@ dependencies = [ "tokio", "tokio-process", "tokio-serial", - "tokio-signal", "tokio-socketcan", "toml 0.5.8", "url", diff --git a/Cargo.toml b/Cargo.toml index 20e5fef..e6e9123 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,7 +55,6 @@ url = "1.7.2" which = "2.0.1" zip = "0.5.2" termcolor = "1.0.4" -tokio-signal = "0.2.7" [target.'cfg(target_os = "linux")'.dependencies] tokio-socketcan = "0.1.3" diff --git a/src/main.rs b/src/main.rs index 13fd47f..fff573e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,11 +19,10 @@ // SOFTWARE. use failure::Error; -use futures::{sync::oneshot, Future, Sink, Stream}; +use futures::{Future, Sink, Stream}; use rogcat::{parser, record::Record}; use std::{process::exit, str::FromStr}; -use tokio::runtime::Runtime; -use tokio_signal::ctrl_c; +use tokio::runtime::current_thread::Runtime; use url::Url; mod cli; @@ -92,36 +91,26 @@ fn run() -> Result<(), Error> { let filter = filter::from_args_profile(&args, &profile)?; let mut parser = parser::Parser::default(); - let mut runtime = Runtime::new()?; - - let f = source - .map(move |a| match a { - StreamData::Line(l) => parser.parse(&l), - StreamData::Record(r) => r, - }) - .filter(move |r| filter.filter(r)) - .take_while(move |_| { - Ok(match head { - Some(0) => false, - Some(n) => { - head = Some(n - 1); - true - } - None => true, + Runtime::new()?.block_on( + source + .map(move |a| match a { + StreamData::Line(l) => parser.parse(&l), + StreamData::Record(r) => r, }) - }) - .forward(sink) - .map(|_| exit(0)) - .map_err(|e| eprintln!("{}", e)); - let mut f = Some(oneshot::spawn(f, &runtime.executor())); - - // Cancel stream processing on ctrl-c - runtime.block_on(ctrl_c().flatten_stream().take(1).for_each(move |()| { - f.take(); - Ok(()) - }))?; - - Ok(()) + .filter(move |r| filter.filter(r)) + .take_while(move |_| { + Ok(match head { + Some(0) => false, + Some(n) => { + head = Some(n - 1); + true + } + None => true, + }) + }) + .forward(sink) + .map(|_| exit(0)), + ) } fn main() {