pub struct TaskListSync { /* private fields */ }Expand description
Synchronization wrapper for a TaskList.
Manages automatic background synchronization of a TaskList using anti-entropy gossip. Changes are propagated via deltas published to a gossip topic.
Implementations§
Source§impl TaskListSync
impl TaskListSync
Sourcepub fn new(
task_list: TaskList,
pubsub: Arc<PubSubManager>,
topic: String,
sync_interval_secs: u64,
) -> Result<Self>
pub fn new( task_list: TaskList, pubsub: Arc<PubSubManager>, topic: String, sync_interval_secs: u64, ) -> Result<Self>
Create a new TaskList synchronization manager.
§Arguments
task_list- The TaskList to synchronizepubsub- Pub/sub manager for gossip messagingtopic- Topic name for pub/sub (typically task list ID)sync_interval_secs- How often to run anti-entropy (seconds)
§Returns
A new TaskListSync instance ready to start.
§Errors
Returns an error if initialization fails.
§Example
let task_list = TaskList::new(id, "My List".to_string(), peer_id);
let sync = TaskListSync::new(
task_list,
pubsub,
"tasklist-abc123".to_string(),
30, // Sync every 30 seconds
)?;Sourcepub async fn apply_remote_delta(
&self,
peer_id: PeerId,
delta: TaskListDelta,
) -> Result<()>
pub async fn apply_remote_delta( &self, peer_id: PeerId, delta: TaskListDelta, ) -> Result<()>
Apply a delta received from a remote peer.
This is called when a delta is received via the gossip topic. The delta is merged into the local TaskList using CRDT semantics.
§Arguments
peer_id- The peer who sent this deltadelta- The delta to apply
§Returns
Ok(()) if the delta was applied successfully.
§Errors
Returns an error if the merge fails.
Sourcepub async fn publish_delta(
&self,
local_peer_id: PeerId,
delta: TaskListDelta,
) -> Result<()>
pub async fn publish_delta( &self, local_peer_id: PeerId, delta: TaskListDelta, ) -> Result<()>
Sourcepub async fn read(&self) -> RwLockReadGuard<'_, TaskList>
pub async fn read(&self) -> RwLockReadGuard<'_, TaskList>
Get a read-only reference to the task list.
Useful for querying the current state without modifying it.
§Returns
A read guard to the TaskList.
Sourcepub async fn write(&self) -> RwLockWriteGuard<'_, TaskList>
pub async fn write(&self) -> RwLockWriteGuard<'_, TaskList>
Get a mutable reference to the task list.
Use this to make local changes. After modifying, call publish_delta
to propagate changes to peers.
§Returns
A write guard to the TaskList.
Auto Trait Implementations§
impl Freeze for TaskListSync
impl !RefUnwindSafe for TaskListSync
impl Send for TaskListSync
impl Sync for TaskListSync
impl Unpin for TaskListSync
impl UnsafeUnpin for TaskListSync
impl !UnwindSafe for TaskListSync
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more