From bdf87aadc748c7531041b1f89166ebd64d7c8c26 Mon Sep 17 00:00:00 2001 From: Avinash jain <162804410+avij1109@users.noreply.github.com> Date: Thu, 27 Mar 2025 18:58:20 +0530 Subject: [PATCH] fixed the bug when future restarts the state goes to ready instead of pending (#3617) * fiexed the bug when future restarts the state goes to ready instead of pending * fix typo * Fix future and formatting --------- Co-authored-by: Evan Almloff --- packages/hooks/src/use_resource.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/hooks/src/use_resource.rs b/packages/hooks/src/use_resource.rs index 60977e423..44322105a 100644 --- a/packages/hooks/src/use_resource.rs +++ b/packages/hooks/src/use_resource.rs @@ -29,12 +29,15 @@ where }); let cb = use_callback(move |_| { + // Set the state to Pending when the task is restarted + state.set(UseResourceState::Pending); + // Create the user's task let fut = rc.reset_and_run_in(&mut future); - // Spawn a wrapper task that polls the inner future and watch its dependencies + // Spawn a wrapper task that polls the inner future and watches its dependencies spawn(async move { - // move the future here and pin it so we can poll it + // Move the future here and pin it so we can poll it let fut = fut; pin_mut!(fut);