Split out a foreground and background executor

This commit is contained in:
Nathan Sobo 2023-11-01 13:53:08 -06:00
parent dd1a2a9e44
commit 11b6d9e33a
26 changed files with 165 additions and 150 deletions

View file

@ -652,7 +652,7 @@ impl Buffer {
if !self.is_dirty() {
let reload = self.reload(cx).log_err().map(drop);
task = cx.executor().spawn(reload);
task = cx.background_executor().spawn(reload);
}
}
}
@ -684,7 +684,7 @@ impl Buffer {
let snapshot = self.snapshot();
let mut diff = self.git_diff.clone();
let diff = cx.executor().spawn(async move {
let diff = cx.background_executor().spawn(async move {
diff.update(&diff_base, &snapshot).await;
diff
});
@ -793,7 +793,7 @@ impl Buffer {
let mut syntax_snapshot = syntax_map.snapshot();
drop(syntax_map);
let parse_task = cx.executor().spawn({
let parse_task = cx.background_executor().spawn({
let language = language.clone();
let language_registry = language_registry.clone();
async move {
@ -803,7 +803,7 @@ impl Buffer {
});
match cx
.executor()
.background_executor()
.block_with_timeout(self.sync_parse_timeout, parse_task)
{
Ok(new_syntax_snapshot) => {
@ -866,9 +866,9 @@ impl Buffer {
fn request_autoindent(&mut self, cx: &mut ModelContext<Self>) {
if let Some(indent_sizes) = self.compute_autoindents() {
let indent_sizes = cx.executor().spawn(indent_sizes);
let indent_sizes = cx.background_executor().spawn(indent_sizes);
match cx
.executor()
.background_executor()
.block_with_timeout(Duration::from_micros(500), indent_sizes)
{
Ok(indent_sizes) => self.apply_autoindents(indent_sizes, cx),
@ -1117,7 +1117,7 @@ impl Buffer {
pub fn diff(&self, mut new_text: String, cx: &AppContext) -> Task<Diff> {
let old_text = self.as_rope().clone();
let base_version = self.version();
cx.executor().spawn(async move {
cx.background_executor().spawn(async move {
let old_text = old_text.to_string();
let line_ending = LineEnding::detect(&new_text);
LineEnding::normalize(&mut new_text);
@ -1155,7 +1155,7 @@ impl Buffer {
let old_text = self.as_rope().clone();
let line_ending = self.line_ending();
let base_version = self.version();
cx.executor().spawn(async move {
cx.background_executor().spawn(async move {
let ranges = trailing_whitespace_ranges(&old_text);
let empty = Arc::<str>::from("");
Diff {

View file

@ -559,7 +559,7 @@ async fn test_outline(cx: &mut gpui2::TestAppContext) {
cx: &'a gpui2::TestAppContext,
) -> Vec<(&'a str, Vec<usize>)> {
let matches = cx
.update(|cx| outline.search(query, cx.executor().clone()))
.update(|cx| outline.search(query, cx.background_executor().clone()))
.await;
matches
.into_iter()
@ -1879,7 +1879,7 @@ fn test_serialization(cx: &mut gpui2::AppContext) {
let state = buffer1.read(cx).to_proto();
let ops = cx
.executor()
.background_executor()
.block(buffer1.read(cx).serialize_ops(None, cx));
let buffer2 = cx.build_model(|cx| {
let mut buffer = Buffer::from_proto(1, state, None).unwrap();
@ -1921,7 +1921,7 @@ fn test_random_collaboration(cx: &mut AppContext, mut rng: StdRng) {
let buffer = cx.build_model(|cx| {
let state = base_buffer.read(cx).to_proto();
let ops = cx
.executor()
.background_executor()
.block(base_buffer.read(cx).serialize_ops(None, cx));
let mut buffer = Buffer::from_proto(i as ReplicaId, state, None).unwrap();
buffer
@ -2025,7 +2025,9 @@ fn test_random_collaboration(cx: &mut AppContext, mut rng: StdRng) {
}
50..=59 if replica_ids.len() < max_peers => {
let old_buffer_state = buffer.read(cx).to_proto();
let old_buffer_ops = cx.executor().block(buffer.read(cx).serialize_ops(None, cx));
let old_buffer_ops = cx
.background_executor()
.block(buffer.read(cx).serialize_ops(None, cx));
let new_replica_id = (0..=replica_ids.len() as ReplicaId)
.filter(|replica_id| *replica_id != buffer.read(cx).replica_id())
.choose(&mut rng)