Skip to content

Commit 74be66c

Browse files
author
Zak Stucke
committed
Standardize ScopedFuture::new_untracked like untrack() and untrack_with_diagnostics()
1 parent 3b058e7 commit 74be66c

File tree

3 files changed

+37
-13
lines changed

3 files changed

+37
-13
lines changed

reactive_graph/src/actions/action.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::{
22
computed::{ArcMemo, Memo, ScopedFuture},
33
diagnostics::is_suppressing_resource_load,
4+
graph::untrack,
45
owner::{ArcStoredValue, ArenaItem, Owner},
56
send_wrapper_ext::SendOption,
67
signal::{ArcMappedSignal, ArcRwSignal, MappedSignal, RwSignal},
@@ -207,10 +208,9 @@ where
207208
version: Default::default(),
208209
dispatched: Default::default(),
209210
action_fn: Arc::new(move |input| {
210-
Box::pin(
211-
owner
212-
.with(|| ScopedFuture::new_untracked(action_fn(input))),
213-
)
211+
Box::pin(owner.with(|| {
212+
ScopedFuture::new_untracked(untrack(|| action_fn(input)))
213+
}))
214214
}),
215215
#[cfg(any(debug_assertions, leptos_debuginfo))]
216216
defined_at: Location::caller(),
@@ -385,10 +385,9 @@ where
385385
version: Default::default(),
386386
dispatched: Default::default(),
387387
action_fn: Arc::new(move |input| {
388-
Box::pin(SendWrapper::new(
389-
owner
390-
.with(|| ScopedFuture::new_untracked(action_fn(input))),
391-
))
388+
Box::pin(SendWrapper::new(owner.with(|| {
389+
ScopedFuture::new_untracked(untrack(|| action_fn(input)))
390+
})))
392391
}),
393392
#[cfg(any(debug_assertions, leptos_debuginfo))]
394393
defined_at: Location::caller(),

reactive_graph/src/computed/async_derived/arc_async_derived.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -521,9 +521,10 @@ impl<T: 'static> ArcAsyncDerived<T> {
521521
{
522522
let fun = move || {
523523
let fut = fun();
524-
let fut = ScopedFuture::new_untracked(async move {
525-
SendOption::new(Some(fut.await))
526-
});
524+
let fut =
525+
ScopedFuture::new_untracked_with_diagnostics(async move {
526+
SendOption::new(Some(fut.await))
527+
});
527528
#[cfg(feature = "sandboxed-arenas")]
528529
let fut = Sandboxed::new(fut);
529530
fut

reactive_graph/src/computed/async_derived/mod.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pin_project! {
2525
pub struct ScopedFuture<Fut> {
2626
pub owner: Owner,
2727
pub observer: Option<AnySubscriber>,
28+
pub diagnostics: bool,
2829
#[pin]
2930
pub fut: Fut,
3031
}
@@ -39,6 +40,7 @@ impl<Fut> ScopedFuture<Fut> {
3940
Self {
4041
owner,
4142
observer,
43+
diagnostics: true,
4244
fut,
4345
}
4446
}
@@ -51,6 +53,19 @@ impl<Fut> ScopedFuture<Fut> {
5153
Self {
5254
owner,
5355
observer: None,
56+
diagnostics: false,
57+
fut,
58+
}
59+
}
60+
61+
#[doc(hidden)]
62+
#[track_caller]
63+
pub fn new_untracked_with_diagnostics(fut: Fut) -> Self {
64+
let owner = Owner::current().unwrap_or_default();
65+
Self {
66+
owner,
67+
observer: None,
68+
diagnostics: true,
5469
fut,
5570
}
5671
}
@@ -61,8 +76,17 @@ impl<Fut: Future> Future for ScopedFuture<Fut> {
6176

6277
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
6378
let this = self.project();
64-
this.owner
65-
.with(|| this.observer.with_observer(|| this.fut.poll(cx)))
79+
this.owner.with(|| {
80+
this.observer.with_observer(|| {
81+
#[cfg(debug_assertions)]
82+
let _maybe_guard = if *this.diagnostics {
83+
None
84+
} else {
85+
Some(crate::diagnostics::SpecialNonReactiveZone::enter())
86+
};
87+
this.fut.poll(cx)
88+
})
89+
})
6690
}
6791
}
6892

0 commit comments

Comments
 (0)