From 183dd0beb82b4abc5fcdc43d37459d1b9b559cc0 Mon Sep 17 00:00:00 2001 From: Gregor Reitzenstein Date: Tue, 17 Nov 2020 15:05:51 +0100 Subject: [PATCH] Properly poll the futures and get somewhere. --- src/app.rs | 19 +++++++++++++++---- src/main.rs | 6 +++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/app.rs b/src/app.rs index e87ae17..51c120e 100644 --- a/src/app.rs +++ b/src/app.rs @@ -13,6 +13,8 @@ use crate::input::Inputs; use crate::schema::API; use crate::commands::{CommandParser, Commands}; +use smol::future::FutureExt; + use slog::{ Logger, Drain, @@ -68,7 +70,9 @@ impl<'a, S: Unpin> Sute<'a, S> { Some(("authenticate", m)) => { if let Some(mut api) = self.api.clone() { let log2 = self.log.clone(); + info!(self.log, "Going for an auth trip"); let f = api.authentication().then(move |mut auth| { + info!(log2, "Hey, an auth step!"); auth.mechanisms().map(move |mechs| { info!(log2, "Oh yeah about `authenticate` of yours:"); for mech in mechs { @@ -76,7 +80,10 @@ impl<'a, S: Unpin> Sute<'a, S> { } }) }); - self.future.replace(Box::pin(f)); + let old_f = self.future.replace(Box::pin(f)); + if !old_f.is_none() { + warn!(self.log, "Dropping a future"); + } } else { error!(self.log, "No connection, can't authenticate!"); } @@ -143,9 +150,13 @@ impl <'a, S: Unpin + Signal> Future for Sute<'a, S> { return Poll::Ready(()); } - if let Some(f) = self.future.take() { - pin_mut!(f); - f.poll(cx); + if let Some(mut f) = self.future.take() { + match f.poll(cx) { + Poll::Pending => { + self.future.replace(Box::pin(f)); + }, + _ => {}, + } } if let Poll::Ready(Some(size)) = Pin::new(&mut self.signal).poll_change(cx) { diff --git a/src/main.rs b/src/main.rs index e6ecd0c..a2a6715 100644 --- a/src/main.rs +++ b/src/main.rs @@ -70,11 +70,11 @@ fn main() -> Result<(), io::Error> { let stream = smol::block_on(lex.run(stream_f)); - let (rpc_future, mut api) = schema::bootstrap(log.clone(), stream); + let (rpc_future, api) = schema::bootstrap(log.clone(), stream); let app = app::Sute::new(resize, log.clone(), drain.clone(), Some(api)); - let mut app_state = app.get_state(); + let app_state = app.get_state(); let mut ui_state = ui::UIState::new(app_state, drain); let signal = app.signal(); @@ -92,7 +92,7 @@ fn main() -> Result<(), io::Error> { terminal.resize(tui::layout::Rect::new(0, 0, x,y)).unwrap(); } - terminal.draw(|f| ui::draw_ui(f, &mut ui_state)); + terminal.draw(|f| ui::draw_ui(f, &mut ui_state))?; let mut stream = signal.to_stream(); loop { if let Some(mut state) = stream.next().await {