From 94cb7517d20f2c765c53308824357de501b28a22 Mon Sep 17 00:00:00 2001 From: Pierre Mdawar Date: Mon, 12 Aug 2024 11:27:44 +0300 Subject: [PATCH] refactor!: rename Subs to Subscribers --- README.md | 2 +- broker.go | 4 ++-- broker_test.go | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 492a2b1..0315d66 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/broker.go b/broker.go index deddb94..a667252 100644 --- a/broker.go +++ b/broker.go @@ -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]) diff --git a/broker_test.go b/broker_test.go index a1e1677..029e020 100644 --- a/broker_test.go +++ b/broker_test.go @@ -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) } } @@ -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