Revert "Wait for previous UpdateFollowers message ack before sending new ones"

This reverts commit fe93263ad4.
This commit is contained in:
Antonio Scandurra 2022-11-17 16:57:32 +01:00
parent 8621c88a3c
commit e7e45be6e1
4 changed files with 57 additions and 106 deletions

View file

@ -18,10 +18,7 @@ use collections::{hash_map, HashMap, HashSet};
use dock::{DefaultItemFactory, Dock, ToggleDockButton};
use drag_and_drop::DragAndDrop;
use fs::{self, Fs};
use futures::{
channel::{mpsc, oneshot},
FutureExt, StreamExt,
};
use futures::{channel::oneshot, FutureExt, StreamExt};
use gpui::{
actions,
elements::*,
@ -714,13 +711,14 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
if let Some(followed_item) = self.to_followable_item_handle(cx) {
if let Some(message) = followed_item.to_state_proto(cx) {
workspace.update_followers(proto::update_followers::Variant::CreateView(
proto::View {
workspace.update_followers(
proto::update_followers::Variant::CreateView(proto::View {
id: followed_item.id() as u64,
variant: Some(message),
leader_id: workspace.leader_for_pane(&pane).map(|id| id.0),
},
));
}),
cx,
);
}
}
@ -764,7 +762,7 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
cx.after_window_update({
let pending_update = pending_update.clone();
let pending_update_scheduled = pending_update_scheduled.clone();
move |this, _| {
move |this, cx| {
pending_update_scheduled.store(false, SeqCst);
this.update_followers(
proto::update_followers::Variant::UpdateView(
@ -774,6 +772,7 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
leader_id: leader_id.map(|id| id.0),
},
),
cx,
);
}
});
@ -1082,11 +1081,9 @@ pub struct Workspace {
leader_state: LeaderState,
follower_states_by_leader: FollowerStatesByLeader,
last_leaders_by_pane: HashMap<WeakViewHandle<Pane>, PeerId>,
follower_updates: mpsc::UnboundedSender<proto::update_followers::Variant>,
window_edited: bool,
active_call: Option<(ModelHandle<ActiveCall>, Vec<gpui::Subscription>)>,
_observe_current_user: Task<()>,
_update_followers: Task<Option<()>>,
}
#[derive(Default)]
@ -1169,34 +1166,6 @@ impl Workspace {
}
});
let (follower_updates_tx, mut follower_updates_rx) = mpsc::unbounded();
let _update_followers = cx.spawn_weak(|this, cx| async move {
while let Some(update) = follower_updates_rx.next().await {
let this = this.upgrade(&cx)?;
let update_followers = this.read_with(&cx, |this, cx| {
if let Some(project_id) = this.project.read(cx).remote_id() {
if this.leader_state.followers.is_empty() {
None
} else {
Some(this.client.request(proto::UpdateFollowers {
project_id,
follower_ids:
this.leader_state.followers.iter().map(|f| f.0).collect(),
variant: Some(update),
}))
}
} else {
None
}
});
if let Some(update_followers) = update_followers {
update_followers.await.log_err();
}
}
None
});
let handle = cx.handle();
let weak_handle = cx.weak_handle();
@ -1255,12 +1224,10 @@ impl Workspace {
project,
leader_state: Default::default(),
follower_states_by_leader: Default::default(),
follower_updates: follower_updates_tx,
last_leaders_by_pane: Default::default(),
window_edited: false,
active_call,
_observe_current_user,
_update_followers,
};
this.project_remote_id_changed(this.project.read(cx).remote_id(), cx);
cx.defer(|this, cx| this.update_window_title(cx));
@ -2000,12 +1967,13 @@ impl Workspace {
cx.notify();
}
self.update_followers(proto::update_followers::Variant::UpdateActiveView(
proto::UpdateActiveView {
self.update_followers(
proto::update_followers::Variant::UpdateActiveView(proto::UpdateActiveView {
id: self.active_item(cx).map(|item| item.id() as u64),
leader_id: self.leader_for_pane(&pane).map(|id| id.0),
},
));
}),
cx,
);
}
fn handle_pane_event(
@ -2626,8 +2594,22 @@ impl Workspace {
Ok(())
}
fn update_followers(&self, update: proto::update_followers::Variant) {
let _ = self.follower_updates.unbounded_send(update);
fn update_followers(
&self,
update: proto::update_followers::Variant,
cx: &AppContext,
) -> Option<()> {
let project_id = self.project.read(cx).remote_id()?;
if !self.leader_state.followers.is_empty() {
self.client
.send(proto::UpdateFollowers {
project_id,
follower_ids: self.leader_state.followers.iter().map(|f| f.0).collect(),
variant: Some(update),
})
.log_err();
}
None
}
pub fn leader_for_pane(&self, pane: &ViewHandle<Pane>) -> Option<PeerId> {