diff --git a/src-tauri/tauri-plugin-plugin-runtime/src/manager.rs b/src-tauri/tauri-plugin-plugin-runtime/src/manager.rs index ae46e598..67a4f7b9 100644 --- a/src-tauri/tauri-plugin-plugin-runtime/src/manager.rs +++ b/src-tauri/tauri-plugin-plugin-runtime/src/manager.rs @@ -1,4 +1,3 @@ -use std::time::Duration; use log::{debug, info}; use tauri::{AppHandle, Manager, Runtime}; use tokio::sync::watch::Sender; @@ -33,8 +32,6 @@ impl PluginManager { pub async fn cleanup(&mut self) { self.kill_tx.send_replace(true); - // Give it a sec to get the tx and kill - tokio::time::sleep(Duration::from_millis(500)).await; } pub async fn run_import(&mut self, data: &str) -> Result { diff --git a/src-tauri/tauri-plugin-plugin-runtime/src/nodejs.rs b/src-tauri/tauri-plugin-plugin-runtime/src/nodejs.rs index f3cfc914..5f85b634 100644 --- a/src-tauri/tauri-plugin-plugin-runtime/src/nodejs.rs +++ b/src-tauri/tauri-plugin-plugin-runtime/src/nodejs.rs @@ -3,12 +3,12 @@ use std::process::Command; use std::time::Duration; use command_group::CommandGroup; -use log::{debug, error, info}; +use log::{debug, info}; use rand::distributions::{Alphanumeric, DistString}; use serde; use serde::Deserialize; -use tauri::path::BaseDirectory; use tauri::{AppHandle, Manager, Runtime}; +use tauri::path::BaseDirectory; use tauri_plugin_shell::ShellExt; use tokio::fs; use tokio::sync::watch::Receiver; @@ -70,23 +70,14 @@ pub async fn node_start( .group_spawn() .expect("yaaknode failed to start"); - let kill_rx = kill_rx.clone(); + let mut kill_rx = kill_rx.clone(); // Check on child tokio::spawn(async move { - loop { - // Small sleep so we don't spin lock the CPU - tokio::time::sleep(Duration::from_millis(50)).await; - if let Ok(Some(status)) = child.try_wait() { - error!("Plugin runtime exited status={}", status); - // TODO: Try restarting plugin runtime - break; - } else if *kill_rx.borrow() { - info!("Stopping plugin runtime"); - child.kill().expect("Failed to kill plugin runtime"); - break; - } - } + kill_rx.wait_for(|b| *b == true).await.expect("Kill channel errored"); + info!("Killing plugin runtime"); + child.kill().expect("Failed to kill plugin runtime"); + return; }); let start = std::time::Instant::now();