Start a sync loop blocking the current thread
(&self, shutdown_rx: Option<mpsc::Receiver<()>>)
| 177 | |
| 178 | /// Start a sync loop blocking the current thread |
| 179 | pub fn sync_loop(&self, shutdown_rx: Option<mpsc::Receiver<()>>) { |
| 180 | const RETRY_DUR: Duration = Duration::from_secs(3); |
| 181 | |
| 182 | let shutdown_rx = shutdown_rx |
| 183 | .map(|rx| self.bind_shutdown(rx)) |
| 184 | .or_else(|| self.default_shutdown_signal()); |
| 185 | |
| 186 | debug!(target: LT, "starting sync loop"); |
| 187 | loop { |
| 188 | if let Some(shutdown_rx) = &shutdown_rx { |
| 189 | if shutdown_rx.try_recv() != Err(mpsc::TryRecvError::Empty) { |
| 190 | break; |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | let mut wait_time = self.config.poll_interval; |
| 195 | |
| 196 | if let Err(e) = self.sync() { |
| 197 | // Report the error and try again on the next run, this might be |
| 198 | // a temporary connectivity issue. |
| 199 | warn!(target: LT, "failed syncing with bitcoind: {:?}", e); |
| 200 | wait_time = RETRY_DUR; |
| 201 | } |
| 202 | |
| 203 | // wait for poll_interval seconds or until we receive a sync notification message |
| 204 | // (which can also get triggered through the shutdown signal) |
| 205 | self.sync_chan.1.recv_timeout(wait_time).ok(); |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | /// Start a sync loop in a new background thread. |
| 210 | /// Takes ownership over the app. You can retain a Query instance before calling this. |
no test coverage detected