Skip to main content

powersync/sync/
options.rs

1use std::{sync::Arc, time::Duration};
2
3use crate::sync::connector::BackendConnector;
4
5/// Options controlling how PowerSync connects to a sync service.
6#[derive(Clone)]
7pub struct SyncOptions {
8    /// The connector to fetch credentials from.
9    pub(crate) connector: Arc<dyn BackendConnector>,
10    /// Whether to sync `auto_subscribe: true` streams automatically.
11    pub(crate) include_default_streams: bool,
12    /// The retry delay between sync iterations on errors.
13    pub(crate) retry_delay: Duration,
14}
15
16impl SyncOptions {
17    /// Creates new [SyncOptions] with default options given the [BackendConnector].
18    pub fn new(connector: impl BackendConnector + 'static) -> Self {
19        Self {
20            connector: Arc::new(connector),
21            include_default_streams: true,
22            retry_delay: Duration::from_secs(5),
23        }
24    }
25
26    /// Whether to sync streams that have `auto_subscribe: true`.
27    ///
28    /// This is enabled by default.
29    pub fn set_include_default_streams(&mut self, include: bool) {
30        self.include_default_streams = include;
31    }
32
33    /// Configures the delay after a failed sync iteration (the default is 5 seconds).
34    pub fn with_retry_delay(&mut self, delay: Duration) {
35        self.retry_delay = delay;
36    }
37}