Skip to content

Commit

Permalink
feat(watch): stop watch build/run service for dropped client
Browse files Browse the repository at this point in the history
  • Loading branch information
kkharji committed May 9, 2022
1 parent 79cfc15 commit 10436b2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
22 changes: 22 additions & 0 deletions src/daemon/requests/drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,28 @@ impl Handler for Drop {
async fn handle(self, state: DaemonState) -> Result<()> {
tracing::trace!("{:?}", self);
let (root, pid) = (&self.client.root, self.client.pid);
let watch_state = state.clone();
let watch_root = root.to_string();

// Drop watch service for current client
tokio::spawn(async move {
let mut state = watch_state.lock().await;
let ws = state.get_mut_workspace(&watch_root)?;

if ws.is_watch_service_running() {
let mut stop = false;
if let Some((watch_req, _)) = ws.watch.as_ref() {
if watch_req.client.pid == pid {
stop = true;
}
if stop {
ws.stop_watch_service().await?;
}
}
}
anyhow::Ok(())
});

let mut state = state.lock().await;
state.remove_workspace(root, pid).await
}
Expand Down
3 changes: 1 addition & 2 deletions src/daemon/state/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,7 @@ impl Workspace {
}

async fn update_lua_state(&mut self) -> Result<()> {
tracing::info!("Updating nvim state");
let update_project_state = self.project.nvim_update_state_script()?;

let update_watch_state = format!(
"require'xcodebase.watch'.is_watching = {}",
self.is_watch_service_running()
Expand Down Expand Up @@ -254,6 +252,7 @@ impl Workspace {
handle.abort();
handle.await.unwrap_err().is_cancelled();
tracing::debug!("Watch service stopeed",);
self.update_lua_state().await?;
}
Ok(())
}
Expand Down

0 comments on commit 10436b2

Please sign in to comment.