tests: handle errors properly in examples (#748)

This commit is contained in:
Liran Ringel
2018-11-20 11:10:36 -05:00
committed by Toby Lawrence
parent 477fa5580a
commit 9b1a45cc6a
19 changed files with 144 additions and 119 deletions
+6 -6
View File
@@ -11,7 +11,7 @@ mod platform {
use futures::{Future, Stream};
use tokio_signal::unix::{Signal, SIGINT, SIGTERM};
pub fn main() {
pub fn main() -> Result<(), Box<::std::error::Error>> {
// Create a stream for each of the signals we'd like to handle.
let sigint = Signal::new(SIGINT).flatten_stream();
let sigterm = Signal::new(SIGTERM).flatten_stream();
@@ -27,26 +27,26 @@ mod platform {
(i.e. this binary)"
);
let (item, _rest) = ::tokio::runtime::current_thread::block_on_all(stream.into_future())
.ok()
.unwrap();
.map_err(|_| "failed to wait for signals")?;
// Figure out which signal we received
let item = item.unwrap();
let item = item.ok_or("received no signal")?;
if item == SIGINT {
println!("received SIGINT");
} else {
assert_eq!(item, SIGTERM);
println!("received SIGTERM");
}
Ok(())
}
}
#[cfg(not(unix))]
mod platform {
pub fn main() {}
pub fn main() -> Result<(), Box<::std::error::Error>> {Ok(())}
}
fn main() {
fn main() -> Result<(), Box<std::error::Error>> {
platform::main()
}