mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-08 07:35:01 +03:00
Reworked loop to lower latency and continue throttling until it's out of events
This commit is contained in:
parent
ed3d339dec
commit
4126e977b6
@ -356,32 +356,43 @@ impl TerminalBuilder {
|
||||
use futures::StreamExt;
|
||||
|
||||
while let Some(event) = self.events_rx.next().await {
|
||||
let mut timer = cx.background().timer(Duration::from_millis(2)).fuse();
|
||||
let mut events = vec![event];
|
||||
|
||||
loop {
|
||||
futures::select_biased! {
|
||||
_ = timer => break,
|
||||
event = self.events_rx.next() => {
|
||||
if let Some(event) = event {
|
||||
events.push(event);
|
||||
if events.len() > 100 {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
this.upgrade(&cx)?.update(&mut cx, |this, cx| {
|
||||
for event in events {
|
||||
this.process_event(&event, cx);
|
||||
}
|
||||
//Process the first event immediately for lowered latency
|
||||
this.process_event(&event, cx);
|
||||
});
|
||||
|
||||
smol::future::yield_now().await;
|
||||
'outer: loop {
|
||||
let mut events = vec![];
|
||||
let mut timer = cx.background().timer(Duration::from_millis(4)).fuse();
|
||||
|
||||
loop {
|
||||
futures::select_biased! {
|
||||
_ = timer => break,
|
||||
event = self.events_rx.next() => {
|
||||
if let Some(event) = event {
|
||||
events.push(event);
|
||||
if events.len() > 100 {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
if events.len() == 0 {
|
||||
smol::future::yield_now().await;
|
||||
break 'outer;
|
||||
} else {
|
||||
this.upgrade(&cx)?.update(&mut cx, |this, cx| {
|
||||
for event in events {
|
||||
this.process_event(&event, cx);
|
||||
}
|
||||
});
|
||||
smol::future::yield_now().await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Some(())
|
||||
|
Loading…
Reference in New Issue
Block a user