@@ -19,7 +19,15 @@ use dioxus_lib::{
1919 signals:: CopyValue ,
2020} ;
2121use futures_util:: stream:: { FuturesUnordered , StreamExt } ;
22- use tokio:: { sync:: Notify , time:: Instant } ;
22+ use tokio:: sync:: Notify ;
23+ #[ cfg( not( target_family = "wasm" ) ) ]
24+ use tokio:: time;
25+ #[ cfg( not( target_family = "wasm" ) ) ]
26+ use tokio:: time:: Instant ;
27+ #[ cfg( target_family = "wasm" ) ]
28+ use wasmtimer:: tokio as time;
29+ #[ cfg( target_family = "wasm" ) ]
30+ use web_time:: Instant ;
2331
2432pub trait QueryCapability
2533where
@@ -222,7 +230,7 @@ impl<Q: QueryCapability> QueriesStorage<Q> {
222230 let task = spawn_forever ( async move {
223231 loop {
224232 // Wait as long as the stale time is configured
225- tokio :: time:: sleep ( interval) . await ;
233+ time:: sleep ( interval) . await ;
226234
227235 // Run the query
228236 QueriesStorage :: < Q > :: run_queries ( & [ ( & query_clone, & query_data_clone) ] ) . await ;
@@ -250,7 +258,7 @@ impl<Q: QueryCapability> QueriesStorage<Q> {
250258 if query_data. reactive_contexts . lock ( ) . unwrap ( ) . is_empty ( ) {
251259 * query_data. clean_task . borrow_mut ( ) = spawn_forever ( async move {
252260 // Wait as long as the stale time is configured
253- tokio :: time:: sleep ( query. clean_time ) . await ;
261+ time:: sleep ( query. clean_time ) . await ;
254262
255263 // Finally clear the query
256264 let mut storage = storage_clone. write ( ) ;
@@ -301,18 +309,18 @@ impl<Q: QueryCapability> QueriesStorage<Q> {
301309 for reactive_context in query_data. reactive_contexts . lock ( ) . unwrap ( ) . iter ( ) {
302310 reactive_context. mark_dirty ( ) ;
303311 }
304- }
305312
306- // Notify the suspense task if any
307- if let Some ( suspense_task) = & * query_data. suspense_task . borrow ( ) {
308- suspense_task. notifier . notify_waiters ( ) ;
309- } ;
313+ // Notify the suspense task if any
314+ if let Some ( suspense_task) = & * query_data. suspense_task . borrow ( ) {
315+ suspense_task. notifier . notify_waiters ( ) ;
316+ } ;
317+ }
310318
311319 // Spawn clean up task if there no more reactive contexts
312320 if query_data. reactive_contexts . lock ( ) . unwrap ( ) . is_empty ( ) {
313321 * query_data. clean_task . borrow_mut ( ) = spawn_forever ( async move {
314322 // Wait as long as the stale time is configured
315- tokio :: time:: sleep ( query. clean_time ) . await ;
323+ time:: sleep ( query. clean_time ) . await ;
316324
317325 // Finally clear the query
318326 let mut storage = storage. storage . write ( ) ;
@@ -387,6 +395,11 @@ impl<Q: QueryCapability> QueriesStorage<Q> {
387395 for reactive_context in query_data. reactive_contexts . lock ( ) . unwrap ( ) . iter ( ) {
388396 reactive_context. mark_dirty ( ) ;
389397 }
398+
399+ // Notify the suspense task if any
400+ if let Some ( suspense_task) = & * query_data. suspense_task . borrow ( ) {
401+ suspense_task. notifier . notify_waiters ( ) ;
402+ } ;
390403 } ) ) ;
391404 }
392405
0 commit comments