-
Notifications
You must be signed in to change notification settings - Fork 117
Open
Labels
Milestone
Description
I'm learning about Tokio and was working with some tutorial code like this:
extern crate futures;
extern crate tokio_core;
use std::time::Duration;
use tokio_core::reactor::{Core, Timeout};
use futures::{Future, future};
fn main() {
let mut core = Core::new().unwrap();
let handle = core.handle();
let future = future::ok(())
.and_then(|_| {
println!("Wait ...");
let d = Duration::from_secs(3);
// How do I propagate this error?
Timeout::new(d, &handle).unwrap()
})
.map(|_| println!("Done"));
core.run(future).unwrap();
}
How would you avoid unwrapping the result from Timeout::new
? Why doesn't Timeout::new
just return an immediately failed future if there's a failure during construction? That way you could just return it from the closure directly.
|_| {
println!("Wait ...");
let d = Duration::from_secs(3);
Timeout::new(d, &handle)
}