Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix observer to only attempt to save once on a document change notifi… #76

Merged
merged 1 commit into from
May 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix observer to only attempt to save once on a document change notifi…
…cation, not once per peer connected
heckj committed May 6, 2024
commit f633c087f97dd620949d8a442e8c7ac07981ab0f
5 changes: 4 additions & 1 deletion Sources/AutomergeRepo/Repo.swift
Original file line number Diff line number Diff line change
@@ -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
@@ -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)
}
}
}