From abb7315215558e7101d00b99934cd6fa993c0ac3 Mon Sep 17 00:00:00 2001 From: elkowar <5300871+elkowar@users.noreply.github.com> Date: Mon, 29 Aug 2022 11:51:18 +0200 Subject: [PATCH] Cleanup script-var-handler properly in drop impl --- crates/eww/src/script_var_handler.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/crates/eww/src/script_var_handler.rs b/crates/eww/src/script_var_handler.rs index f5b8bd7..7e20e74 100644 --- a/crates/eww/src/script_var_handler.rs +++ b/crates/eww/src/script_var_handler.rs @@ -286,6 +286,24 @@ impl ListenVarHandler { } } +impl Drop for ListenVarHandler { + fn drop(&mut self) { + if !self.listen_process_handles.is_empty() { + std::thread::scope(|s| { + s.spawn(|| { + let rt = tokio::runtime::Builder::new_current_thread() + .thread_name("listen-var-drop-stop-all") + .build() + .expect("Failed to initialize tokio runtime for script var handlers"); + rt.block_on(async { + self.stop_all().await; + }); + }); + }) + } + } +} + async fn terminate_handle(mut child: tokio::process::Child) { if let Some(id) = child.id() { log::debug!("Killing process with id {}", id);