diff --git a/reactive_graph/src/computed/async_derived/mod.rs b/reactive_graph/src/computed/async_derived/mod.rs index 8d911e9389..06d2a3c375 100644 --- a/reactive_graph/src/computed/async_derived/mod.rs +++ b/reactive_graph/src/computed/async_derived/mod.rs @@ -23,10 +23,11 @@ pin_project! { #[derive(Clone)] #[allow(missing_docs)] pub struct ScopedFuture { - pub owner: Owner, - pub observer: Option, + owner: Owner, + observer: Option, + diagnostics: bool, #[pin] - pub fut: Fut, + fut: Fut, } } @@ -39,6 +40,7 @@ impl ScopedFuture { Self { owner, observer, + diagnostics: true, fut, } } @@ -51,19 +53,19 @@ impl ScopedFuture { Self { owner, observer: None, + diagnostics: false, fut, } } #[doc(hidden)] #[track_caller] - pub fn new_untracked_with_diagnostics( - fut: Fut, - ) -> ScopedFutureUntrackedWithDiagnostics { + pub fn new_untracked_with_diagnostics(fut: Fut) -> Self { let owner = Owner::current().unwrap_or_default(); - ScopedFutureUntrackedWithDiagnostics { + Self { owner, observer: None, + diagnostics: true, fut, } } @@ -75,41 +77,19 @@ impl Future for ScopedFuture { fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { let this = self.project(); this.owner.with(|| { - #[cfg(debug_assertions)] - let _maybe_guard = if this.observer.is_none() { - Some(crate::diagnostics::SpecialNonReactiveZone::enter()) - } else { - None - }; - this.observer.with_observer(|| this.fut.poll(cx)) + this.observer.with_observer(|| { + #[cfg(debug_assertions)] + let _maybe_guard = if *this.diagnostics { + None + } else { + Some(crate::diagnostics::SpecialNonReactiveZone::enter()) + }; + this.fut.poll(cx) + }) }) } } -pin_project! { - /// A [`Future`] wrapper that sets the [`Owner`] and [`Observer`] before polling the inner - /// `Future`, output of [`ScopedFuture::new_untracked_with_diagnostics`]. - /// - /// In leptos 0.9 this will be replaced with `ScopedFuture` itself. - #[derive(Clone)] - pub struct ScopedFutureUntrackedWithDiagnostics { - owner: Owner, - observer: Option, - #[pin] - fut: Fut, - } -} - -impl Future for ScopedFutureUntrackedWithDiagnostics { - type Output = Fut::Output; - - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - let this = self.project(); - this.owner - .with(|| this.observer.with_observer(|| this.fut.poll(cx))) - } -} - /// Utilities used to track whether asynchronous computeds are currently loading. pub mod suspense { use crate::{