mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-08 00:00:13 +02:00
tests: handle errors properly in examples (#748)
This commit is contained in:
committed by
Toby Lawrence
parent
477fa5580a
commit
9b1a45cc6a
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user