mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-17 23:14:03 +01:00
Fix spin lock
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
extern crate core;
|
||||
|
||||
use log::info;
|
||||
use crate::manager::PluginManager;
|
||||
use log::info;
|
||||
use tauri::plugin::{Builder, TauriPlugin};
|
||||
use tauri::{Manager, RunEvent, Runtime, State};
|
||||
use tokio::sync::Mutex;
|
||||
@@ -24,11 +24,12 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
||||
})
|
||||
})
|
||||
.on_event(|app, e| match e {
|
||||
RunEvent::ExitRequested { code, .. } => {
|
||||
// TODO: Also exit when app is force-quit (eg. cmd+r in IntelliJ runner)
|
||||
RunEvent::Exit => {
|
||||
tauri::async_runtime::block_on(async move {
|
||||
info!("Exiting plugin runtime due to app exit {:?}", code);
|
||||
info!("Exiting plugin runtime due to app exit");
|
||||
let manager: State<Mutex<PluginManager>> = app.state();
|
||||
manager.lock().await.cleanup();
|
||||
manager.lock().await.cleanup().await;
|
||||
});
|
||||
}
|
||||
_ => {}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use std::time::Duration;
|
||||
use log::{debug, info};
|
||||
use tauri::{AppHandle, Manager, Runtime};
|
||||
use tokio::sync::watch::Sender;
|
||||
@@ -30,8 +31,10 @@ impl PluginManager {
|
||||
PluginManager { client, kill_tx }
|
||||
}
|
||||
|
||||
pub fn cleanup(&mut self) {
|
||||
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<HookResponse, String> {
|
||||
|
||||
@@ -75,6 +75,7 @@ pub async fn node_start<R: Runtime>(
|
||||
// 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);
|
||||
|
||||
Reference in New Issue
Block a user