Merge pull request #32 from hexedtech/fix/workspace-leave-bool

fix: leave_workspace returns like detach
This commit is contained in:
frelodev 2024-10-01 19:26:48 +02:00 committed by GitHub
commit 238dd22b78
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View file

@ -182,7 +182,10 @@ impl Client {
/// Leave the [`Workspace`] with the given name. /// Leave the [`Workspace`] with the given name.
pub fn leave_workspace(&self, id: &str) -> bool { 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. /// Gets a [`Workspace`] handle by name.

View file

@ -100,6 +100,11 @@ impl Workspace {
Ok(ws) 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. /// Create a new buffer in the current workspace.
pub async fn create(&self, path: &str) -> RemoteResult<()> { pub async fn create(&self, path: &str) -> RemoteResult<()> {
let mut workspace_client = self.0.services.ws(); let mut workspace_client = self.0.services.ws();
@ -312,6 +317,7 @@ impl Workspace {
let weak = Arc::downgrade(&self.0); let weak = Arc::downgrade(&self.0);
let name = self.id(); let name = self.id();
tokio::spawn(async move { tokio::spawn(async move {
tracing::debug!("workspace worker starting");
loop { loop {
// TODO can we stop responsively rather than poll for Arc being dropped? // TODO can we stop responsively rather than poll for Arc being dropped?
if weak.upgrade().is_none() { if weak.upgrade().is_none() {
@ -359,6 +365,7 @@ impl Workspace {
} }
} }
} }
tracing::debug!("workspace worker stopping");
}); });
} }
} }