mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-11 12:46:07 +00:00
Pause and buffer
This commit is contained in:
parent
86406153bd
commit
bb8263104c
3 changed files with 23 additions and 17 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -5368,6 +5368,7 @@ dependencies = [
|
|||
"settings",
|
||||
"shellexpand",
|
||||
"smallvec",
|
||||
"smol",
|
||||
"theme",
|
||||
"thiserror",
|
||||
"util",
|
||||
|
|
|
@ -17,6 +17,7 @@ settings = { path = "../settings" }
|
|||
workspace = { path = "../workspace" }
|
||||
project = { path = "../project" }
|
||||
smallvec = { version = "1.6", features = ["union"] }
|
||||
smol = "1.2.5"
|
||||
mio-extras = "2.0.6"
|
||||
futures = "0.3"
|
||||
ordered-float = "2.1.1"
|
||||
|
|
|
@ -19,10 +19,7 @@ use alacritty_terminal::{
|
|||
};
|
||||
use anyhow::{bail, Result};
|
||||
|
||||
use futures::{
|
||||
channel::mpsc::{unbounded, UnboundedReceiver, UnboundedSender},
|
||||
future,
|
||||
};
|
||||
use futures::channel::mpsc::{unbounded, UnboundedReceiver, UnboundedSender};
|
||||
|
||||
use modal::deploy_modal;
|
||||
use settings::{Settings, Shell};
|
||||
|
@ -350,25 +347,32 @@ impl TerminalBuilder {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn subscribe(self, cx: &mut ModelContext<Terminal>) -> Terminal {
|
||||
pub fn subscribe(mut self, cx: &mut ModelContext<Terminal>) -> Terminal {
|
||||
//Event loop
|
||||
cx.spawn_weak(|this, mut cx| async move {
|
||||
use futures::StreamExt;
|
||||
|
||||
self.events_rx
|
||||
.for_each(|event| {
|
||||
match this.upgrade(&cx) {
|
||||
Some(this) => {
|
||||
this.update(&mut cx, |this, cx| {
|
||||
this.process_event(&event, cx);
|
||||
});
|
||||
}
|
||||
None => {}
|
||||
let mut events = Vec::new();
|
||||
while let Some(event) = self.events_rx.next().await {
|
||||
events.push(event);
|
||||
while let Ok(Some(event)) = self.events_rx.try_next() {
|
||||
events.push(event);
|
||||
if events.len() > 1000 {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
future::ready(())
|
||||
})
|
||||
.await;
|
||||
let this = this.upgrade(&cx)?;
|
||||
this.update(&mut cx, |this, cx| {
|
||||
for event in events.drain(..) {
|
||||
this.process_event(&event, cx);
|
||||
}
|
||||
});
|
||||
|
||||
smol::future::yield_now().await;
|
||||
}
|
||||
|
||||
Some(())
|
||||
})
|
||||
.detach();
|
||||
|
||||
|
|
Loading…
Reference in a new issue