From f69514aaf25bd37c903324e71f13faaec8956b24 Mon Sep 17 00:00:00 2001 From: marc2332 Date: Mon, 8 Jan 2024 17:02:10 +0100 Subject: [PATCH] enhancements --- .../wallet/core/operations/background_syncing.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sdk/src/wallet/core/operations/background_syncing.rs b/sdk/src/wallet/core/operations/background_syncing.rs index 044136add8..4b9015a09b 100644 --- a/sdk/src/wallet/core/operations/background_syncing.rs +++ b/sdk/src/wallet/core/operations/background_syncing.rs @@ -15,7 +15,7 @@ pub(crate) const DEFAULT_BACKGROUNDSYNCING_INTERVAL: Duration = Duration::from_s #[derive(Clone, PartialEq, Debug)] pub(crate) enum BackgroundSyncStatus { - NotRunning, + Stopped, Running, Stopping, } @@ -49,16 +49,16 @@ where tx_background_sync.send(BackgroundSyncStatus::Running).ok(); let wallet = self.clone(); + let interval_seconds = interval.unwrap_or(DEFAULT_BACKGROUNDSYNCING_INTERVAL); task::spawn(async move { loop { log::debug!("[background_syncing]: syncing wallet"); - if let Err(err) = wallet.sync(options.clone()).await { + if let Err(err) = wallet.sync(interval_seconds.clone()).await { log::debug!("[background_syncing] error: {}", err) } - let seconds = interval.unwrap_or(DEFAULT_BACKGROUNDSYNCING_INTERVAL); let res = timeout(seconds, async { rx_background_sync .wait_for(|status| *status == BackgroundSyncStatus::Stopping) @@ -73,7 +73,7 @@ where break; } } - tx_background_sync.send(BackgroundSyncStatus::NotRunning).ok(); + tx_background_sync.send(BackgroundSyncStatus::Stopped).ok(); log::debug!("[background_syncing]: stopped"); }); Ok(()) @@ -94,17 +94,17 @@ where let mut rx_background_sync = self.background_syncing_status.1.clone(); - // immediately return if not running - if *rx_background_sync.borrow() == BackgroundSyncStatus::NotRunning { + // immediately return if is stopped + if *rx_background_sync.borrow() == BackgroundSyncStatus::Stopped { return Ok(()); } // send stop request self.request_stop_background_syncing(); - // wait until it stopped + // wait until it has stopped rx_background_sync - .wait_for(|status| *status == BackgroundSyncStatus::NotRunning) + .wait_for(|status| *status == BackgroundSyncStatus::Stopped) .await .ok();