Skip to content

Commit

Permalink
chore: rename to NotifyReceivedChanges
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Meier <[email protected]>
  • Loading branch information
astromechza committed Oct 26, 2024
1 parent ecfb75d commit 1c90e55
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/http2writer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func mainInner() error {
} else if _, err := doc.Commit("commit"); err != nil {
panic(err)
}
a.NotifyPossibleChanges()
a.NotifyReceivedChanges()
}
}()

Expand Down
6 changes: 3 additions & 3 deletions read.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
"github.com/automerge/automerge-go"
)

// NotifyPossibleChanges should be called after the shared doc has "received" a message. This allows any goroutines that
// NotifyReceivedChanges should be called after the shared doc has "received" a message. This allows any goroutines that
// are generating messages to be preempted and know that new messaged may be available. This is a broadcast because
// any number of goroutines may be writing changes to the doc to their client.
func (b *SharedDoc) NotifyPossibleChanges() {
func (b *SharedDoc) NotifyReceivedChanges() {
b.mutex.Lock()
defer b.mutex.Unlock()
for _, channel := range b.channels {
Expand Down Expand Up @@ -44,7 +44,7 @@ func (b *SharedDoc) consumeMessagesFromReader(ctx context.Context, state *autome
received += 1
receivedChanges += len(m.Changes())
receivedBytes += len(sc.Bytes()) + 1
b.NotifyPossibleChanges()
b.NotifyReceivedChanges()

if terminationCheck(state.Doc, m) {
log.InfoContext(ctx, "termination check met")
Expand Down
6 changes: 3 additions & 3 deletions read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
func TestNotifyPossibleChanges_no_subs(t *testing.T) {
t.Parallel()
a := NewSharedDoc(automerge.New())
a.NotifyPossibleChanges()
a.NotifyReceivedChanges()
}

func TestNotifyPossibleChanges_with_sub(t *testing.T) {
Expand All @@ -33,7 +33,7 @@ func TestNotifyPossibleChanges_with_sub(t *testing.T) {
})

t.Run("message available after notify", func(t *testing.T) {
a.NotifyPossibleChanges()
a.NotifyReceivedChanges()

select {
case v := <-sub:
Expand All @@ -45,7 +45,7 @@ func TestNotifyPossibleChanges_with_sub(t *testing.T) {

t.Run("closer function close channel", func(t *testing.T) {
fin()
a.NotifyPossibleChanges()
a.NotifyReceivedChanges()
_, ok := <-sub
assertEqual(t, false, ok)
})
Expand Down

0 comments on commit 1c90e55

Please sign in to comment.