diff --git a/packages/liveview/Cargo.toml b/packages/liveview/Cargo.toml index dac3ea6b6..6e3036c3c 100644 --- a/packages/liveview/Cargo.toml +++ b/packages/liveview/Cargo.toml @@ -41,8 +41,9 @@ tower = { workspace = true } dioxus = { workspace = true } [features] -default = ["hot-reload"] +default = ["hot-reload", "multi-thread"] axum = ["dep:axum"] +multi-thread = ["tokio/rt-multi-thread"] hot-reload = ["dioxus-hot-reload"] [[example]] diff --git a/packages/liveview/src/launch.rs b/packages/liveview/src/launch.rs index 994e32769..2adbb5212 100644 --- a/packages/liveview/src/launch.rs +++ b/packages/liveview/src/launch.rs @@ -9,22 +9,23 @@ pub fn launch( contexts: Vec Box + Send + Sync>>, platform_config: Config, ) { - tokio::runtime::Builder::new_multi_thread() - .enable_all() - .build() - .unwrap() - .block_on(async move { - platform_config - .with_virtual_dom(move || { - let mut virtual_dom = VirtualDom::new(root); + #[cfg(feature = "multi-threaded")] + let mut builder = tokio::runtime::Builder::new_multi_thread(); + #[cfg(not(feature = "multi-threaded"))] + let mut builder = tokio::runtime::Builder::new_current_thread(); - for context in &contexts { - virtual_dom.insert_any_root_context(context()); - } + builder.enable_all().build().unwrap().block_on(async move { + platform_config + .with_virtual_dom(move || { + let mut virtual_dom = VirtualDom::new(root); - virtual_dom - }) - .launch() - .await; - }); + for context in &contexts { + virtual_dom.insert_any_root_context(context()); + } + + virtual_dom + }) + .launch() + .await; + }); }