diff --git a/src/reactor/global.rs b/src/reactor/global.rs index cd0f84e76..b295326c9 100644 --- a/src/reactor/global.rs +++ b/src/reactor/global.rs @@ -49,6 +49,6 @@ impl Drop for HelperThread { fn run(mut reactor: Reactor, done: Arc) { while !done.load(Ordering::SeqCst) { - reactor.turn(None); + reactor.turn(None).unwrap(); } } diff --git a/src/reactor/mod.rs b/src/reactor/mod.rs index a29803027..a52894ec0 100644 --- a/src/reactor/mod.rs +++ b/src/reactor/mod.rs @@ -144,23 +144,25 @@ impl Reactor { /// /// # Return value /// - /// This function returns an instance of `Turn` which as of today has no - /// extra information with it and can be safely discarded. In the future - /// this return value may contain information about what happened while this + /// This function returns an instance of `Turn` or `io::Error`. + /// + /// `Turn` as of today has no extra information with it and can be safely discarded. + /// In the future `Turn` may contain information about what happened while this /// reactor blocked. - pub fn turn(&mut self, max_wait: Option) -> Turn { - self.poll(max_wait); - Turn { _priv: () } + /// + /// `io::Error` is possible when there is an internal `tokio` bug or I/O error. + pub fn turn(&mut self, max_wait: Option) -> io::Result { + self.poll(max_wait)?; + Ok(Turn { _priv: () }) } - fn poll(&mut self, max_wait: Option) { + fn poll(&mut self, max_wait: Option) -> io::Result<()> { // Block waiting for an event to happen, peeling out how many events // happened. match self.inner.io.poll(&mut self.events, max_wait) { Ok(_) => {} - Err(ref e) if e.kind() == ErrorKind::Interrupted => return, - // TODO: This should return an io::Result instead of panic. - Err(e) => panic!("error in poll: {}", e), + Err(ref e) if e.kind() == ErrorKind::Interrupted => return Ok(()), + Err(e) => return Err(e), } // Process all the events that came in, dispatching appropriately @@ -176,6 +178,8 @@ impl Reactor { self.dispatch(token, event.readiness()); } } + + Ok(()) } fn dispatch(&mut self, token: mio::Token, ready: mio::Ready) { diff --git a/tests/wakeup.rs b/tests/wakeup.rs index 490e6491f..e507ee3f5 100644 --- a/tests/wakeup.rs +++ b/tests/wakeup.rs @@ -10,13 +10,13 @@ use tokio::reactor::Reactor; fn works() { let mut r = Reactor::new().unwrap(); r.handle().wakeup(); - r.turn(None); + r.turn(None).unwrap(); let now = Instant::now(); let mut n = 0; while now.elapsed() < Duration::from_millis(10) { n += 1; - r.turn(Some(Duration::from_millis(10))); + r.turn(Some(Duration::from_millis(10))).unwrap(); } assert!(n < 5); } @@ -37,7 +37,7 @@ fn wakes() { for _ in 0..N { tx.send(()).unwrap(); - r.turn(None); + r.turn(None).unwrap(); } t.join().unwrap(); }