Skip to content

Commit

Permalink
gracefully handle lack of tokio runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalkuthe committed Jun 8, 2024
1 parent f16dd6a commit 418ac23
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion helix-event/src/debounce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit 418ac23

Please sign in to comment.