Skip to content

Commit

Permalink
fix observer to only attempt to save once on a document change notifi…
Browse files Browse the repository at this point in the history
…cation, not once per peer connected (#76)
  • Loading branch information
heckj authored May 6, 2024
1 parent f23c184 commit 4cd6edb
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Sources/AutomergeRepo/Repo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ public final class Repo {

// MARK: Synchronization Pieces - Observe internal docs

/// Creates an observer, if one doesn't already exist, to watch for `objectWillChange`
/// notifications from the Automerge document.
/// - Parameter id: The document Id to track with this observer
func watchDocForChanges(id: DocumentId) {
guard let handle = handles[id] else {
// no such document in our set of document handles
Expand All @@ -314,10 +317,10 @@ public final class Repo {
let handleObserver = doc.objectWillChange
.sink { [weak self] _ in
guard let self else { return }
self.saveSignalPublisher.send(id)
for peer in self.peerMetadataByPeerId.keys {
Task {
await self.beginSync(docId: id, to: peer)
self.saveSignalPublisher.send(id)
}
}
}
Expand Down

0 comments on commit 4cd6edb

Please # to comment.