@@ -10,16 +10,24 @@ use std::{
1010 time:: Duration ,
1111} ;
1212
13- use :: warnings:: Warning ;
14- use dioxus_lib:: prelude:: Task ;
15- use dioxus_lib:: prelude:: * ;
16- use dioxus_lib:: signals:: { Readable , Writable } ;
17- use dioxus_lib:: {
13+ use dioxus:: prelude:: * ;
14+ use dioxus:: {
1815 hooks:: { use_memo, use_reactive} ,
1916 signals:: CopyValue ,
2017} ;
18+ use dioxus_core:: {
19+ provide_root_context, spawn_forever, use_drop, ReactiveContext , SuspendedFuture , Task ,
20+ } ;
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,13 +230,12 @@ 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 ;
229237 }
230- } )
231- . expect ( "Failed to spawn interval task." ) ;
238+ } ) ;
232239 * interval_task = Some ( ( interval, task) ) ;
233240 }
234241
@@ -248,14 +255,14 @@ impl<Q: QueryCapability> QueriesStorage<Q> {
248255
249256 // Spawn clean up task if there no more reactive contexts
250257 if query_data. reactive_contexts . lock ( ) . unwrap ( ) . is_empty ( ) {
251- * query_data. clean_task . borrow_mut ( ) = spawn_forever ( async move {
258+ * query_data. clean_task . borrow_mut ( ) = Some ( spawn_forever ( async move {
252259 // Wait as long as the stale time is configured
253- tokio :: time:: sleep ( query. clean_time ) . await ;
260+ time:: sleep ( query. clean_time ) . await ;
254261
255262 // Finally clear the query
256263 let mut storage = storage_clone. write ( ) ;
257264 storage. remove ( & query) ;
258- } ) ;
265+ } ) ) ;
259266 }
260267 }
261268
@@ -301,23 +308,23 @@ impl<Q: QueryCapability> QueriesStorage<Q> {
301308 for reactive_context in query_data. reactive_contexts . lock ( ) . unwrap ( ) . iter ( ) {
302309 reactive_context. mark_dirty ( ) ;
303310 }
304- }
305311
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- } ;
312+ // Notify the suspense task if any
313+ if let Some ( suspense_task) = & * query_data. suspense_task . borrow ( ) {
314+ suspense_task. notifier . notify_waiters ( ) ;
315+ } ;
316+ }
310317
311318 // Spawn clean up task if there no more reactive contexts
312319 if query_data. reactive_contexts . lock ( ) . unwrap ( ) . is_empty ( ) {
313- * query_data. clean_task . borrow_mut ( ) = spawn_forever ( async move {
320+ * query_data. clean_task . borrow_mut ( ) = Some ( spawn_forever ( async move {
314321 // Wait as long as the stale time is configured
315- tokio :: time:: sleep ( query. clean_time ) . await ;
322+ time:: sleep ( query. clean_time ) . await ;
316323
317324 // Finally clear the query
318325 let mut storage = storage. storage . write ( ) ;
319326 storage. remove ( & query) ;
320- } ) ;
327+ } ) ) ;
321328 }
322329
323330 QueryReader {
@@ -387,6 +394,11 @@ impl<Q: QueryCapability> QueriesStorage<Q> {
387394 for reactive_context in query_data. reactive_contexts . lock ( ) . unwrap ( ) . iter ( ) {
388395 reactive_context. mark_dirty ( ) ;
389396 }
397+
398+ // Notify the suspense task if any
399+ if let Some ( suspense_task) = & * query_data. suspense_task . borrow ( ) {
400+ suspense_task. notifier . notify_waiters ( ) ;
401+ } ;
390402 } ) ) ;
391403 }
392404
@@ -597,9 +609,6 @@ impl<Q: QueryCapability> UseQuery<Q> {
597609 Q :: Ok : Clone ,
598610 Q :: Err : Clone ,
599611 {
600- let _allow_write_in_component_body =
601- :: warnings:: Allow :: new ( warnings:: signal_write_in_component_body:: ID ) ;
602-
603612 let storage = consume_context :: < QueriesStorage < Q > > ( ) ;
604613 let mut storage = storage. storage . write_unchecked ( ) ;
605614 let query_data = storage. get_mut ( & self . query . peek ( ) ) . unwrap ( ) ;
0 commit comments