use executor::current_thread::CurrentThread;
use runtime::current_thread::Runtime;
use tokio_reactor::Reactor;
use tokio_timer::clock::Clock;
use tokio_timer::timer::Timer;
use std::io;
#[derive(Debug)]
pub struct Builder {
clock: Clock,
}
impl Builder {
pub fn new() -> Builder {
Builder {
clock: Clock::new(),
}
}
pub fn clock(&mut self, clock: Clock) -> &mut Self {
self.clock = clock;
self
}
pub fn build(&mut self) -> io::Result<Runtime> {
let reactor = Reactor::new()?;
let reactor_handle = reactor.handle();
let timer = Timer::new_with_now(reactor, self.clock.clone());
let timer_handle = timer.handle();
let executor = CurrentThread::new_with_park(timer);
let runtime = Runtime::new2(
reactor_handle,
timer_handle,
self.clock.clone(),
executor);
Ok(runtime)
}
}