From 386fa371d708f8e91a83762dfc7a58971681e091 Mon Sep 17 00:00:00 2001 From: Pascal Kuthe Date: Fri, 5 Apr 2024 03:25:41 +0200 Subject: [PATCH] gracefully handle lack of tokio runtime --- helix-event/src/debounce.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/helix-event/src/debounce.rs b/helix-event/src/debounce.rs index 30b6f671be71..5971f72b30cf 100644 --- a/helix-event/src/debounce.rs +++ b/helix-event/src/debounce.rs @@ -28,7 +28,10 @@ pub trait AsyncHook: Sync + Send + 'static + Sized { // so it should only be reached in case of total CPU overload. // However, a bounded channel is much more efficient so it's nice to use here let (tx, rx) = mpsc::channel(128); - tokio::spawn(run(self, rx)); + // only spawn worker if we are inside runtime to avoid having to spawn a runtime for unrelated unit tests + if tokio::runtime::Handle::try_current().is_ok() { + tokio::spawn(run(self, rx)); + } tx } }