Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

language_model: Stream background events through async-channel (#66290)

Ben Brandt33156f0d81f3
diff --git a/Cargo.lock b/Cargo.lock
index 3d9de6a982c..de13e50ff4f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -9545,6 +9545,7 @@ name = "language_model"
version = "0.1.0"
dependencies = [
"anyhow",
+ "async-channel 2.5.0",
"base64 0.22.1",
"collections",
"credentials_provider",
diff --git a/crates/language_model/Cargo.toml b/crates/language_model/Cargo.toml
index 5993dcdedc2..49e015f4d06 100644
--- a/crates/language_model/Cargo.toml
+++ b/crates/language_model/Cargo.toml
@@ -17,6 +17,7 @@ test-support = []
[dependencies]
anyhow.workspace = true
+async-channel.workspace = true
base64.workspace = true
collections.workspace = true
credentials_provider.workspace = true
diff --git a/crates/language_model/src/language_model.rs b/crates/language_model/src/language_model.rs
index 679cd8b6569..7eb4f7254f3 100644
--- a/crates/language_model/src/language_model.rs
+++ b/crates/language_model/src/language_model.rs
@@ -8,8 +8,8 @@ pub mod fake_provider;
pub use language_model_core::*;
use anyhow::Result;
-use futures::{FutureExt, SinkExt};
-use futures::{StreamExt, channel::mpsc, future::BoxFuture, stream::BoxStream};
+use futures::FutureExt;
+use futures::{StreamExt, future::BoxFuture, stream::BoxStream};
use gpui::{AnyView, App, AsyncApp, BackgroundExecutor, Task, Window};
use icons::IconName;
use parking_lot::Mutex;
@@ -35,7 +35,10 @@ pub fn stream_in_background<Output>(
where
Output: Send + 'static,
{
- let (mut sender, receiver) = mpsc::channel(BACKGROUND_STREAM_BUFFER_SIZE);
+ // `futures::channel::mpsc` parks a full sender behind a `std` mutex that the
+ // receiver also locks, which traps when the receiver polls on the browser's
+ // main thread.
+ let (sender, receiver) = async_channel::bounded(BACKGROUND_STREAM_BUFFER_SIZE);
let task = executor.spawn(async move {
while let Some(event) = events.next().await {
if sender.send(event).await.is_err() {