Skip to content

Commit

Permalink
enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 committed Jan 8, 2024
1 parent 70f4bd4 commit f69514a
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions sdk/src/wallet/core/operations/background_syncing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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)
Expand All @@ -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(())
Expand All @@ -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();

Expand Down

0 comments on commit f69514a

Please sign in to comment.