Skip to content

Commit

Permalink
refactor!: rename Subs to Subscribers
Browse files Browse the repository at this point in the history
  • Loading branch information
mdawar committed Aug 12, 2024
1 parent 0f7632d commit 94cb751
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ topics := broker.Topics()
topicsCount := broker.NumTopics()

// Get the subscribers count on a specific topic.
count := broker.Subs("events")
count := broker.Subscribers("events")
```

## Tests
Expand Down
4 changes: 2 additions & 2 deletions broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func (b *Broker[T, P]) NumTopics() int {
return len(b.subs)
}

// Subs returns the number of subscriptions on the specified topic.
func (b *Broker[T, P]) Subs(topic T) int {
// Subscribers returns the number of subscriptions on the specified topic.
func (b *Broker[T, P]) Subscribers(topic T) int {
b.mu.RLock()
defer b.mu.RUnlock()
return len(b.subs[topic])
Expand Down
6 changes: 3 additions & 3 deletions broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,14 @@ func TestBrokerNumTopicsWithSubscribersOnSameTopic(t *testing.T) {
assertTopics(0)
}

func TestBrokerSubs(t *testing.T) {
func TestBrokerSubscribers(t *testing.T) {
t.Parallel()

broker := pubsub.NewBroker[string, string]()

assertSubs := func(topic string, want int) {
t.Helper()
if got := broker.Subs(topic); want != got {
if got := broker.Subscribers(topic); want != got {
t.Fatalf("want %d subscriptions on topic %q, got %d", want, topic, got)
}
}
Expand Down Expand Up @@ -661,7 +661,7 @@ func TestBrokerConcurrentPublishSubscribe(t *testing.T) {
waitUntil(time.Second, func() bool {
var total int
for _, topic := range topics {
total += broker.Subs(topic)
total += broker.Subscribers(topic)
}

return total == totalSubsCount
Expand Down

0 comments on commit 94cb751

Please sign in to comment.