fix: leave_workspace returns like detach

This commit is contained in:
əlemi 2024-09-26 05:11:44 +02:00 committed by alemi.dev
parent b585708f8d
commit 6afbb23590
2 changed files with 11 additions and 1 deletions

View file

@ -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.

View file

@ -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");
});
}
}