Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: leave_workspace returns like detach #32

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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() {
Expand Down Expand Up @@ -359,6 +365,7 @@ impl Workspace {
}
}
}
tracing::debug!("workspace worker stopping");
});
}
}