Skip to content

Commit

Permalink
Merge pull request #26 from nunogoncalves03/main
Browse files Browse the repository at this point in the history
Fix code sample in Syncing and Concurrency section
  • Loading branch information
ConradIrwin authored Feb 13, 2024
2 parents b80ce8a + 2cfd538 commit b7d9d51
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions automerge.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,25 +120,32 @@ in sync. This wraps an underlying efficient sync protocol to minimize both
round-trips and bandwidth used.
//* process 1 *
syncState, err := automerge.NewSyncState(doc)
syncState := automerge.NewSyncState(doc)
for {
m, valid, err := syncState.GenerateMessage()
m, valid := syncState.GenerateMessage()
if valid {
sendCh <- m
sendCh <- m.Bytes()
}
msg := <-recvCh
err := syncState.ReceiveMessage(msg)
_, err := syncState.ReceiveMessage(msg)
if err != nil {
panic(err)
}
}
//* process 2 *
syncState, err := automerge.NewSyncState(doc)
syncState := automerge.NewSyncState(doc)
for {
msg := <-sendCh
err := syncState.ReceiveMessage(msg)
_, err := syncState.ReceiveMessage(msg)
if err != nil {
panic(err)
}
m, valid, err := syncState.GenerateMessage()
m, valid := syncState.GenerateMessage()
if valid {
recvCh <- m
recvCh <- m.Bytes()
}
}
Expand Down

0 comments on commit b7d9d51

Please sign in to comment.