diff --git a/packages/dioxus-blitz/src/application.rs b/packages/dioxus-blitz/src/application.rs index c6c41000..10db473a 100644 --- a/packages/dioxus-blitz/src/application.rs +++ b/packages/dioxus-blitz/src/application.rs @@ -46,7 +46,7 @@ impl ApplicationHandler for Application { // Initialise pending windows for window_config in self.pending_windows.drain(..) { - let mut view = View::init(window_config, event_loop, &self.proxy, &self.rt); + let mut view = View::init(window_config, event_loop, &self.proxy); view.resume(&self.rt); if !view.renderer.is_active() { continue; diff --git a/packages/dioxus-blitz/src/window.rs b/packages/dioxus-blitz/src/window.rs index 81134a71..90bcef3b 100644 --- a/packages/dioxus-blitz/src/window.rs +++ b/packages/dioxus-blitz/src/window.rs @@ -15,7 +15,6 @@ use blitz_dom::util::Resource; use blitz_net::AsyncProvider; use std::sync::Arc; use std::task::Waker; -use tokio::runtime::Runtime; use winit::dpi::LogicalSize; use winit::event::{ElementState, MouseButton}; use winit::event_loop::{ActiveEventLoop, EventLoopProxy}; @@ -85,11 +84,10 @@ impl View { config: WindowConfig, event_loop: &ActiveEventLoop, proxy: &EventLoopProxy, - rt: &Runtime, ) -> Self { let winit_window = Arc::from(event_loop.create_window(config.attributes).unwrap()); - rt.spawn(Arc::clone(&config.net).resolve(proxy.clone(), winit_window.id())); + Arc::clone(&config.net).resolve(proxy.clone(), winit_window.id()); // TODO: make this conditional on text input focus winit_window.set_ime_allowed(true); diff --git a/packages/net/Cargo.toml b/packages/net/Cargo.toml index 840f48f0..4b1b8198 100644 --- a/packages/net/Cargo.toml +++ b/packages/net/Cargo.toml @@ -17,6 +17,6 @@ tracing = "0.1.40" thiserror = "1.0.63" [features] -default = ["non_blocking"] +default = [] blocking = ["dep:ureq"] non_blocking = ["dep:tokio", "dep:winit", "dep:futures-util", "dep:reqwest"] \ No newline at end of file diff --git a/packages/net/src/provider/non_blocking.rs b/packages/net/src/provider/non_blocking.rs index 12b65bef..f38a2a59 100644 --- a/packages/net/src/provider/non_blocking.rs +++ b/packages/net/src/provider/non_blocking.rs @@ -19,7 +19,7 @@ pub struct AsyncProvider { client: Client, futures: Mutex>>, } -impl AsyncProvider { +impl AsyncProvider { pub fn new(rt: &Runtime) -> Self { Self { rt: rt.handle().clone(), @@ -27,32 +27,34 @@ impl AsyncProvider { futures: Mutex::new(FuturesUnordered::new()), } } - pub async fn resolve>( + pub fn resolve + Send>( self: Arc, event_loop_proxy: EventLoopProxy

, window_id: WindowId, ) { - let mut interval = tokio::time::interval(Duration::from_millis(100)); + self.rt.clone().spawn(async move { + let mut interval = tokio::time::interval(Duration::from_millis(100)); - 'thread: loop { - interval.tick().await; - while let Some(ir) = self.futures.lock().await.next().await { - match ir { - Ok(Ok(t)) => { - let e = event_loop_proxy.send_event((window_id, t).into()); - if e.is_err() { - break 'thread; + 'thread: loop { + interval.tick().await; + while let Some(ir) = self.futures.lock().await.next().await { + match ir { + Ok(Ok(t)) => { + let e = event_loop_proxy.send_event((window_id, t).into()); + if e.is_err() { + break 'thread; + } + } + Ok(Err(e)) => { + tracing::error!("Fetch failed with {e:?}") + } + Err(e) => { + tracing::error!("Fetch thread failed with {e}") } - } - Ok(Err(e)) => { - tracing::error!("Fetch failed with {e:?}") - } - Err(e) => { - tracing::error!("Fetch thread failed with {e}") } } } - } + }); } } impl AsyncProvider {