Properly poll the futures and get somewhere.

This commit is contained in:
Gregor Reitzenstein 2020-11-17 15:05:51 +01:00
parent f8160f5b16
commit 183dd0beb8
2 changed files with 18 additions and 7 deletions

View File

@ -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<Item=(u16,u16)>> 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) {

View File

@ -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 {