mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-13 05:42:59 +00:00
Use watch::Sender::borrow_mut
instead of send
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
af6e931da7
commit
6c3551bff1
2 changed files with 11 additions and 16 deletions
|
@ -31,7 +31,7 @@ pub struct ChatPanel {
|
||||||
channel_select: ViewHandle<Select>,
|
channel_select: ViewHandle<Select>,
|
||||||
settings: watch::Receiver<Settings>,
|
settings: watch::Receiver<Settings>,
|
||||||
local_timezone: UtcOffset,
|
local_timezone: UtcOffset,
|
||||||
_status_observer: Task<()>,
|
_observe_status: Task<()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Event {}
|
pub enum Event {}
|
||||||
|
@ -99,7 +99,7 @@ impl ChatPanel {
|
||||||
cx.dispatch_action(LoadMoreMessages);
|
cx.dispatch_action(LoadMoreMessages);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let _status_observer = cx.spawn(|this, mut cx| {
|
let _observe_status = cx.spawn(|this, mut cx| {
|
||||||
let mut status = rpc.status();
|
let mut status = rpc.status();
|
||||||
async move {
|
async move {
|
||||||
while let Some(_) = status.recv().await {
|
while let Some(_) = status.recv().await {
|
||||||
|
@ -117,7 +117,7 @@ impl ChatPanel {
|
||||||
channel_select,
|
channel_select,
|
||||||
settings,
|
settings,
|
||||||
local_timezone: cx.platform().local_timezone(),
|
local_timezone: cx.platform().local_timezone(),
|
||||||
_status_observer,
|
_observe_status,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.init_active_channel(cx);
|
this.init_active_channel(cx);
|
||||||
|
|
|
@ -6,7 +6,6 @@ use gpui::{AsyncAppContext, Entity, ModelContext, Task};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use postage::prelude::Stream;
|
use postage::prelude::Stream;
|
||||||
use postage::sink::Sink;
|
|
||||||
use postage::watch;
|
use postage::watch;
|
||||||
use std::any::TypeId;
|
use std::any::TypeId;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
@ -94,10 +93,9 @@ impl Client {
|
||||||
self.state.read().status.1.clone()
|
self.state.read().status.1.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn set_status(&self, status: Status) -> Result<()> {
|
fn set_status(&self, status: Status) {
|
||||||
let mut state = self.state.write();
|
let mut state = self.state.write();
|
||||||
state.status.0.send(status).await?;
|
*state.status.0.borrow_mut() = status;
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn subscribe_from_model<T, M, F>(
|
pub fn subscribe_from_model<T, M, F>(
|
||||||
|
@ -167,14 +165,14 @@ impl Client {
|
||||||
let (user_id, access_token) = Self::login(cx.platform(), &cx.background()).await?;
|
let (user_id, access_token) = Self::login(cx.platform(), &cx.background()).await?;
|
||||||
let user_id = user_id.parse::<u64>()?;
|
let user_id = user_id.parse::<u64>()?;
|
||||||
|
|
||||||
self.set_status(Status::Connecting).await?;
|
self.set_status(Status::Connecting);
|
||||||
match self.connect(user_id, &access_token, cx).await {
|
match self.connect(user_id, &access_token, cx).await {
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
log::info!("connected to rpc address {}", *ZED_SERVER_URL);
|
log::info!("connected to rpc address {}", *ZED_SERVER_URL);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
self.set_status(Status::ConnectionError).await?;
|
self.set_status(Status::ConnectionError);
|
||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -259,20 +257,17 @@ impl Client {
|
||||||
self.set_status(Status::Connected {
|
self.set_status(Status::Connected {
|
||||||
connection_id,
|
connection_id,
|
||||||
user_id,
|
user_id,
|
||||||
})
|
});
|
||||||
.await?;
|
|
||||||
|
|
||||||
let handle_io = cx.background().spawn(handle_io);
|
let handle_io = cx.background().spawn(handle_io);
|
||||||
let this = self.clone();
|
let this = self.clone();
|
||||||
cx.foreground()
|
cx.foreground()
|
||||||
.spawn(async move {
|
.spawn(async move {
|
||||||
match handle_io.await {
|
match handle_io.await {
|
||||||
Ok(()) => {
|
Ok(()) => this.set_status(Status::Disconnected),
|
||||||
let _ = this.set_status(Status::Disconnected).await;
|
|
||||||
}
|
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
log::error!("connection error: {:?}", err);
|
log::error!("connection error: {:?}", err);
|
||||||
let _ = this.set_status(Status::ConnectionLost).await;
|
this.set_status(Status::ConnectionLost);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -365,7 +360,7 @@ impl Client {
|
||||||
pub async fn disconnect(&self) -> Result<()> {
|
pub async fn disconnect(&self) -> Result<()> {
|
||||||
let conn_id = self.connection_id()?;
|
let conn_id = self.connection_id()?;
|
||||||
self.peer.disconnect(conn_id).await;
|
self.peer.disconnect(conn_id).await;
|
||||||
self.set_status(Status::Disconnected).await?;
|
self.set_status(Status::Disconnected);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue