mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-01-31 00:35:19 +01:00
Fix busy loop (#14839)
* refactor(tauri-cli): remove unneeded Arc<Mutex> * fix(tauri-cli): remove busy-looping
This commit is contained in:
@@ -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)]
|
||||||
|
|||||||
@@ -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)?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user