Reworked loop to lower latency and continue throttling until it's out of events

This commit is contained in:
Mikayla Maki 2022-08-03 12:18:11 -07:00
parent ed3d339dec
commit 4126e977b6

View file

@ -356,8 +356,14 @@ impl TerminalBuilder {
use futures::StreamExt; use futures::StreamExt;
while let Some(event) = self.events_rx.next().await { while let Some(event) = self.events_rx.next().await {
let mut timer = cx.background().timer(Duration::from_millis(2)).fuse(); this.upgrade(&cx)?.update(&mut cx, |this, cx| {
let mut events = vec![event]; //Process the first event immediately for lowered latency
this.process_event(&event, cx);
});
'outer: loop {
let mut events = vec![];
let mut timer = cx.background().timer(Duration::from_millis(4)).fuse();
loop { loop {
futures::select_biased! { futures::select_biased! {
@ -375,14 +381,19 @@ impl TerminalBuilder {
} }
} }
if events.len() == 0 {
smol::future::yield_now().await;
break 'outer;
} else {
this.upgrade(&cx)?.update(&mut cx, |this, cx| { this.upgrade(&cx)?.update(&mut cx, |this, cx| {
for event in events { for event in events {
this.process_event(&event, cx); this.process_event(&event, cx);
} }
}); });
smol::future::yield_now().await; smol::future::yield_now().await;
} }
}
}
Some(()) Some(())
}) })