futuretest/src/main.rs

52 lines
1.2 KiB
Rust

#![feature(conservative_impl_trait)]
extern crate futures;
extern crate tokio_core;
use futures::future::{self, FutureResult};
use futures::future::*;
use tokio_core::reactor::Core;
#[derive(Debug)]
enum ErrorCode
{
CanHandleWithAsync,
CanHandleWithSync,
CannotHandle
}
#[derive(Debug)]
enum ErrorCode2
{
}
fn main() {
let mut core = Core::new().expect("Failed to initialize tokio_core reactor!");
let f = async_entry_point()
.or_else(move |err| {
//the problem is that the three matches below resolve to different future types
match err {
ErrorCode::CanHandleWithAsync => async_error_handler()
.map_err(|_| ErrorCode::CannotHandle).wait(),
ErrorCode::CanHandleWithSync => future::result(sync_error_handler()),
ErrorCode::CannotHandle => future::err(ErrorCode::CannotHandle),
}
})
;
core.run(f).unwrap();
}
fn async_entry_point() -> FutureResult<(), ErrorCode> {
future::ok(())
}
fn async_error_handler() -> FutureResult<(), ErrorCode2> {
future::ok(())
}
fn sync_error_handler() -> Result<(), ErrorCode> {
Ok(())
}