From 9667d37c9043d23def44a236b305b865118c381e Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 9 Jul 2019 03:23:17 -0400 Subject: the state shouldn't exit if there is a polling error --- src/state.rs | 23 +++++++++++++++++------ src/tui.rs | 9 +++------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/state.rs b/src/state.rs index b9707c0..f6c8a78 100644 --- a/src/state.rs +++ b/src/state.rs @@ -104,13 +104,8 @@ impl State { eprint!("command exited: {}\r\n", status); Ok(()) } -} - -impl futures::future::Future for State { - type Item = (); - type Error = Error; - fn poll(&mut self) -> futures::Poll { + fn poll_with_errors(&mut self) -> futures::Poll<(), Error> { loop { let mut did_work = false; @@ -175,6 +170,22 @@ impl futures::future::Future for State { } } +impl futures::future::Future for State { + type Item = (); + type Error = (); + + fn poll(&mut self) -> futures::Poll { + loop { + match self.poll_with_errors() { + Ok(a) => return Ok(a), + Err(e) => { + eprint!("error polling state: {}\r\n", e); + } + } + } + } +} + struct Command { future: crate::eval::Eval, res: futures::sync::oneshot::Sender<()>, diff --git a/src/tui.rs b/src/tui.rs index b7af752..6708340 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -11,9 +11,6 @@ pub enum Error { #[snafu(display("error during eval: {}", source))] Eval { source: crate::eval::Error }, - #[snafu(display("error during print: {}", source))] - Print { source: crate::state::Error }, - #[snafu(display("error during sending: {}", source))] Sending { source: futures::sync::mpsc::SendError, @@ -29,9 +26,9 @@ pub fn tui() { tokio::run(futures::lazy(|| { let (w, r) = futures::sync::mpsc::channel(0); - tokio::spawn(crate::state::State::new(r).map_err(|e| { - error(&Error::Print { source: e }); - })); + tokio::spawn( + crate::state::State::new(r).map_err(|()| unreachable!()), + ); futures::future::loop_fn(0, move |idx| { let w = w.clone(); -- cgit v1.2.3-54-g00ecf