aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-07-09 03:23:17 -0400
committerJesse Luehrs <doy@tozt.net>2019-07-09 03:25:38 -0400
commit9667d37c9043d23def44a236b305b865118c381e (patch)
tree23d3042fb3eeee80b115a25ea43f0ac4a81e6d99
parent09396b0ffdc8d4fdee11da7db8b951d3575408d4 (diff)
downloadnbsh-old-9667d37c9043d23def44a236b305b865118c381e.tar.gz
nbsh-old-9667d37c9043d23def44a236b305b865118c381e.zip
the state shouldn't exit if there is a polling error
-rw-r--r--src/state.rs23
-rw-r--r--src/tui.rs9
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<Self::Item, Self::Error> {
+ 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<Self::Item, Self::Error> {
+ 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<crate::state::StateEvent>,
@@ -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();