From 6afbb23590f14db7573b324ffc3faae2cf06541d Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 26 Sep 2024 05:11:44 +0200 Subject: [PATCH] fix: leave_workspace returns like detach --- src/client.rs | 5 ++++- src/workspace.rs | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/client.rs b/src/client.rs index 2d4d03a..7cba102 100644 --- a/src/client.rs +++ b/src/client.rs @@ -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. diff --git a/src/workspace.rs b/src/workspace.rs index 69170fe..9f1fc2c 100644 --- a/src/workspace.rs +++ b/src/workspace.rs @@ -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(); @@ -312,6 +317,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() { @@ -359,6 +365,7 @@ impl Workspace { } } } + tracing::debug!("workspace worker stopping"); }); } }