Skip to content

Commit 1149ff4

Browse files
committed
Don't try launching a tokio runtime if we are already within one
1 parent 2e7e069 commit 1149ff4

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

packages/desktop/src/launch.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,20 @@ pub fn launch_virtual_dom_blocking(virtual_dom: VirtualDom, mut desktop_config:
115115
pub fn launch_virtual_dom(virtual_dom: VirtualDom, desktop_config: Config) -> ! {
116116
#[cfg(feature = "tokio_runtime")]
117117
{
118-
tokio::runtime::Builder::new_multi_thread()
119-
.enable_all()
120-
.build()
121-
.unwrap()
122-
.block_on(tokio::task::unconstrained(async move {
123-
launch_virtual_dom_blocking(virtual_dom, desktop_config)
124-
}));
125-
126-
unreachable!("The desktop launch function will never exit")
118+
if let std::result::Result::Ok(handle) = tokio::runtime::Handle::try_current() {
119+
assert_ne!(handle.runtime_flavor(), tokio::runtime::RuntimeFlavor::CurrentThread, "Current thread runtime does not allow event handling");
120+
launch_virtual_dom_blocking(virtual_dom, desktop_config);
121+
} else {
122+
tokio::runtime::Builder::new_multi_thread()
123+
.enable_all()
124+
.build()
125+
.unwrap()
126+
.block_on(tokio::task::unconstrained(async move {
127+
launch_virtual_dom_blocking(virtual_dom, desktop_config)
128+
}));
129+
130+
unreachable!("The desktop launch function will never exit")
131+
}
127132
}
128133

129134
#[cfg(not(feature = "tokio_runtime"))]

0 commit comments

Comments
 (0)