From 33a8f0f592b86c2559ebbe5c47a8d1878dce0b93 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 23 Oct 2024 11:08:08 +0200 Subject: [PATCH] Loader: use AsyncAbortGuard Signed-off-by: Dietmar Maurer --- src/state/loader.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/state/loader.rs b/src/state/loader.rs index 6904a9b..8a75b64 100644 --- a/src/state/loader.rs +++ b/src/state/loader.rs @@ -12,7 +12,7 @@ use crate::props::{IntoLoadCallback, LoadCallback}; use crate::state::{SharedState, SharedStateObserver, SharedStateReadGuard, SharedStateWriteGuard}; use crate::widget::{error_message, Button, Container, Fa}; -use super::StorageLocation; +use super::{AsyncAbortGuard, StorageLocation}; /// Shared HTTP load state /// @@ -21,6 +21,7 @@ pub struct LoaderState { loading: u64, state_id: Option, storage_location: StorageLocation, + async_abort_guard: Option, pub loader: Option>, pub data: Option, Error>>, } @@ -75,6 +76,7 @@ impl Loader { data: None, loader: None, storage_location: StorageLocation::Session, + async_abort_guard: None, }; Self(SharedState::new(state)) } @@ -176,13 +178,15 @@ impl Loader { self.write().loading += 1; let me = self.clone(); - wasm_bindgen_futures::spawn_local(async move { + + self.write().async_abort_guard = Some(AsyncAbortGuard::spawn(async move { let res = loader.apply().await; let mut me = me.write(); + me.async_abort_guard = None; me.loading -= 1; me.data = Some(res.map(|data| Rc::new(data))); me.store_to_cache(); - }); + })); } pub fn reload_button(&self) -> Button { -- 2.39.5