Return error when waiting on a worktree snapshot after disconnecting

This commit is contained in:
Antonio Scandurra 2022-11-28 17:43:40 +01:00
parent cd0b663f62
commit af2a2d2494

View File

@ -81,6 +81,7 @@ pub struct RemoteWorktree {
replica_id: ReplicaId, replica_id: ReplicaId,
diagnostic_summaries: TreeMap<PathKey, DiagnosticSummary>, diagnostic_summaries: TreeMap<PathKey, DiagnosticSummary>,
visible: bool, visible: bool,
disconnected: bool,
} }
#[derive(Clone)] #[derive(Clone)]
@ -248,6 +249,7 @@ impl Worktree {
client: client.clone(), client: client.clone(),
diagnostic_summaries: Default::default(), diagnostic_summaries: Default::default(),
visible, visible,
disconnected: false,
}) })
}); });
@ -1069,6 +1071,7 @@ impl RemoteWorktree {
pub fn disconnected_from_host(&mut self) { pub fn disconnected_from_host(&mut self) {
self.updates_tx.take(); self.updates_tx.take();
self.snapshot_subscriptions.clear(); self.snapshot_subscriptions.clear();
self.disconnected = true;
} }
pub fn update_from_remote(&mut self, update: proto::UpdateWorktree) { pub fn update_from_remote(&mut self, update: proto::UpdateWorktree) {
@ -1083,10 +1086,12 @@ impl RemoteWorktree {
self.scan_id > scan_id || (self.scan_id == scan_id && self.is_complete) self.scan_id > scan_id || (self.scan_id == scan_id && self.is_complete)
} }
fn wait_for_snapshot(&mut self, scan_id: usize) -> impl Future<Output = ()> { fn wait_for_snapshot(&mut self, scan_id: usize) -> impl Future<Output = Result<()>> {
let (tx, rx) = oneshot::channel(); let (tx, rx) = oneshot::channel();
if self.observed_snapshot(scan_id) { if self.observed_snapshot(scan_id) {
let _ = tx.send(()); let _ = tx.send(());
} else if self.disconnected {
drop(tx);
} else { } else {
match self match self
.snapshot_subscriptions .snapshot_subscriptions
@ -1097,7 +1102,8 @@ impl RemoteWorktree {
} }
async move { async move {
let _ = rx.await; rx.await?;
Ok(())
} }
} }
@ -1126,7 +1132,7 @@ impl RemoteWorktree {
) -> Task<Result<Entry>> { ) -> Task<Result<Entry>> {
let wait_for_snapshot = self.wait_for_snapshot(scan_id); let wait_for_snapshot = self.wait_for_snapshot(scan_id);
cx.spawn(|this, mut cx| async move { cx.spawn(|this, mut cx| async move {
wait_for_snapshot.await; wait_for_snapshot.await?;
this.update(&mut cx, |worktree, _| { this.update(&mut cx, |worktree, _| {
let worktree = worktree.as_remote_mut().unwrap(); let worktree = worktree.as_remote_mut().unwrap();
let mut snapshot = worktree.background_snapshot.lock(); let mut snapshot = worktree.background_snapshot.lock();
@ -1145,7 +1151,7 @@ impl RemoteWorktree {
) -> Task<Result<()>> { ) -> Task<Result<()>> {
let wait_for_snapshot = self.wait_for_snapshot(scan_id); let wait_for_snapshot = self.wait_for_snapshot(scan_id);
cx.spawn(|this, mut cx| async move { cx.spawn(|this, mut cx| async move {
wait_for_snapshot.await; wait_for_snapshot.await?;
this.update(&mut cx, |worktree, _| { this.update(&mut cx, |worktree, _| {
let worktree = worktree.as_remote_mut().unwrap(); let worktree = worktree.as_remote_mut().unwrap();
let mut snapshot = worktree.background_snapshot.lock(); let mut snapshot = worktree.background_snapshot.lock();