Skip to content

Commit

Permalink
fix: leave_workspace returns like detach
Browse files Browse the repository at this point in the history
  • Loading branch information
alemidev committed Sep 29, 2024
1 parent f03995c commit fa655af
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,10 @@ impl Client {

/// Leave the [`Workspace`] with the given name.
pub fn leave_workspace(&self, id: &str) -> bool {
self.0.workspaces.remove(id).is_some()
match self.0.workspaces.remove(id) {
None => true,
Some(x) => x.1.consume(),
}
}

/// Gets a [`Workspace`] handle by name.
Expand Down
7 changes: 7 additions & 0 deletions src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ impl Workspace {
Ok(ws)
}

/// drop arc, return true if was last
pub(crate) fn consume(self) -> bool {
Arc::into_inner(self.0).is_some()
}

/// Create a new buffer in the current workspace.
pub async fn create(&self, path: &str) -> RemoteResult<()> {
let mut workspace_client = self.0.services.ws();
Expand Down Expand Up @@ -311,6 +316,7 @@ impl Workspace {
let weak = Arc::downgrade(&self.0);
let name = self.id();
tokio::spawn(async move {
tracing::debug!("workspace worker starting");
loop {
// TODO can we stop responsively rather than poll for Arc being dropped?
if weak.upgrade().is_none() { break };
Expand Down Expand Up @@ -354,6 +360,7 @@ impl Workspace {
}
}
}
tracing::debug!("workspace worker stopping");
});
}
}

0 comments on commit fa655af

Please sign in to comment.