Fix busy loop (#14839)

* refactor(tauri-cli):  remove unneeded Arc<Mutex>

* fix(tauri-cli): remove busy-looping
This commit is contained in:
sftse
2026-01-29 04:13:03 +01:00
committed by GitHub
parent e3fdcb5002
commit 32576120fd
4 changed files with 4 additions and 20 deletions

View File

@@ -16,7 +16,6 @@ pub use rust::{MobileOptions, Options, Rust as AppInterface, WatcherOptions};
pub trait DevProcess { pub trait DevProcess {
fn kill(&self) -> std::io::Result<()>; fn kill(&self) -> std::io::Result<()>;
fn try_wait(&self) -> std::io::Result<Option<ExitStatus>>;
#[allow(unused)] #[allow(unused)]
fn wait(&self) -> std::io::Result<ExitStatus>; fn wait(&self) -> std::io::Result<ExitStatus>;
#[allow(unused)] #[allow(unused)]

View File

@@ -514,9 +514,7 @@ impl Rust {
run: F, run: F,
dirs: &Dirs, dirs: &Dirs,
) -> crate::Result<()> { ) -> crate::Result<()> {
let child = run(self, config)?; let mut child = run(self, config)?;
let process = Arc::new(Mutex::new(child));
let (tx, rx) = sync_channel(1); let (tx, rx) = sync_channel(1);
let watch_folders = get_watch_folders(additional_watch_folders, dirs.tauri)?; let watch_folders = get_watch_folders(additional_watch_folders, dirs.tauri)?;
@@ -581,17 +579,12 @@ impl Rust {
display_path(event_path.strip_prefix(dirs.frontend).unwrap_or(event_path)) display_path(event_path.strip_prefix(dirs.frontend).unwrap_or(event_path))
); );
let mut p = process.lock().unwrap(); child.kill().context("failed to kill app process")?;
p.kill().context("failed to kill app process")?;
// wait for the process to exit // wait for the process to exit
// note that on mobile, kill() already waits for the process to exit (duct implementation) // note that on mobile, kill() already waits for the process to exit (duct implementation)
loop { let _ = child.wait();
if !matches!(p.try_wait(), Ok(None)) { child = run(self, config)?;
break;
}
}
*p = run(self, config)?;
} }
} }
} }

View File

@@ -33,10 +33,6 @@ impl DevProcess for DevChild {
Ok(()) Ok(())
} }
fn try_wait(&self) -> std::io::Result<Option<ExitStatus>> {
self.dev_child.try_wait()
}
fn wait(&self) -> std::io::Result<ExitStatus> { fn wait(&self) -> std::io::Result<ExitStatus> {
self.dev_child.wait() self.dev_child.wait()
} }

View File

@@ -72,10 +72,6 @@ impl DevProcess for DevChild {
Ok(()) Ok(())
} }
fn try_wait(&self) -> std::io::Result<Option<ExitStatus>> {
self.child.try_wait().map(|res| res.map(|o| o.status))
}
fn wait(&self) -> std::io::Result<ExitStatus> { fn wait(&self) -> std::io::Result<ExitStatus> {
self.child.wait().map(|o| o.status) self.child.wait().map(|o| o.status)
} }