diff --git a/src/lib.rs b/src/lib.rs index 7e83a33..3a2641d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,6 +16,7 @@ pub enum Error { NotImplementedError, UnknownError, Error(BoxedError), + TimeoutError, } impl From for Error { @@ -39,6 +40,7 @@ impl fmt::Display for Error { NotImplementedError => write!(f, "Functionality is not implemented yet"), UnknownError => write!(f, "Unknown error occurrred"), Error(ref e) => write!(f, "Error: {}", e), + TimeoutError => write!(f, "Timeout"), } } } @@ -134,16 +136,17 @@ impl Application { self.window.quit() } - pub fn wait_for_message(&mut self, timeout: Option) -> Result<(), Error> { + pub fn wait_for_message(&mut self) -> Result<(), Error> { + self.try_wait(Duration::new(u64::MAX, 0)) + } + + pub fn try_wait(&mut self, timeout: Duration) -> Result<(), Error> { loop { let msg; - match self - .rx - .recv_timeout(timeout.unwrap_or_else(|| Duration::new(u64::MAX, 0))) - { + match self.rx.recv_timeout(timeout) { Ok(m) => msg = m, // Yield and wait for the next poll - Err(RecvTimeoutError::Timeout) => break, + Err(RecvTimeoutError::Timeout) => return Err(Error::TimeoutError), Err(RecvTimeoutError::Disconnected) => { self.quit(); break;