From 5b33e0051a03243c5aedf53ff8531e123978fab9 Mon Sep 17 00:00:00 2001 From: Greg Johnston Date: Fri, 29 Sep 2023 13:50:12 -0400 Subject: [PATCH] warnings too --- leptos_reactive/src/runtime.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/leptos_reactive/src/runtime.rs b/leptos_reactive/src/runtime.rs index 597b96a75c..7ee69b43e5 100644 --- a/leptos_reactive/src/runtime.rs +++ b/leptos_reactive/src/runtime.rs @@ -1533,9 +1533,6 @@ impl ScopedFuture { } /// Runs the future in the current [`Owner`]'s scope context. - /// - /// # Panics - /// Panics if there is no current [`Owner`] context available. #[track_caller] pub fn new_current(fut: Fut) -> Result { Owner::current() @@ -1546,16 +1543,21 @@ impl ScopedFuture { /// Runs a future that has access to the provided [`Owner`]'s /// scope context. +#[track_caller] pub fn spawn_local_with_owner( owner: Owner, fut: impl Future + 'static, ) { let scoped_future = ScopedFuture::new(owner, fut); + #[cfg(debug_assertions)] + let loc = std::panic::Location::caller(); crate::spawn_local(async move { if scoped_future.await.is_none() { - // TODO: should we warn here? - // /* warning message */ + crate::macros::debug_warn!( + "`spawn_local_with_owner` called at {loc} returned `None`, \ + i.e., its Owner was disposed before the `Future` resolved." + ); } }); } @@ -1570,11 +1572,15 @@ pub fn spawn_local_with_current_owner( fut: impl Future + 'static, ) -> Result<(), ScopedFutureError> { let scoped_future = ScopedFuture::new_current(fut)?; + #[cfg(debug_assertions)] + let loc = std::panic::Location::caller(); crate::spawn_local(async move { if scoped_future.await.is_none() { - // TODO: should we warn here? - // /* warning message */ + crate::macros::debug_warn!( + "`spawn_local_with_owner` called at {loc} returned `None`, \ + i.e., its Owner was disposed before the `Future` resolved." + ); } });